https://bugs.llvm.org/show_bug.cgi?id=36033

            Bug ID: 36033
           Summary: __builtin_choose_expr vs. ?:, not a constant
                    expression for _Static_assert
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: other
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangb...@nondot.org
          Reporter: oliver.klei...@c-01a.de
                CC: llvm-bugs@lists.llvm.org

Created attachment 19718
  --> https://bugs.llvm.org/attachment.cgi?id=19718&action=edit
example program code

The result of __builtin_choose_expr is not considered a constant expression by
_Static_assert if the selected expression is not really constant (const
variable)
An expression that uses the conditional operator with a constant condition in
place of __builtin_choose_expr is, however, considered constant by
_Static_assert.

This seems to be the result of some constant folding order.

Examples follow, also attached.

int main(void) {
    const int a = 1;
    _Static_assert(a, "Error");

    _Static_assert(a ? a : 1, "Error");

    _Static_assert(
        __builtin_constant_p(1) ? a : 1, "Ok");

    _Static_assert(
        __builtin_constant_p(a) ? a : 1, "Ok");

    _Static_assert(
        __builtin_choose_expr(
            __builtin_constant_p(1), 1, 1), "Ok");

    _Static_assert(
        __builtin_choose_expr(
            __builtin_constant_p(1), a, 1), "Error, should be Ok?");

    _Static_assert(
        __builtin_choose_expr(
            __builtin_constant_p(a), a, 1), "Error, should be Ok?");
    return 0;
}

I don't know what the intended behaviour is, but I would assume the third,
fourth, and last two cases to behave similarly. (In the sense of what is
considered constant, not necessarily in the sense of which expression is
selected.) GCC rejects the third case and, accepts the last case where it
selects the second expression.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to