https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121666

            Bug ID: 121666
           Summary: __builtin_expect_with_probability accepts non constant
                    expression
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent at vvhe dot ca
  Target Milestone: ---

In the documentation, it says that the probability must be a constant floating
point expression, so why does gcc accept the following code? It this a bug or a
feature that is not documented?

double rand_impl();

void foo (int i){
    __builtin_expect_with_probability (i, 0, rand_impl());
}


Also, clang rejects the code from above for not being a constant expression:
https://godbolt.org/z/Eh7x4q3xr.

Reply via email to