[llvm-bugs] [Bug 36033] New: __builtin_choose_expr vs. ?:, not a constant expression for _Static_assert

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jan 21 17:17:47 PST 2018


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: unassignedclangbugs at nondot.org
          Reporter: oliver.kleinke at c-01a.de
                CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180122/5e21cb3f/attachment-0001.html>


More information about the llvm-bugs mailing list