<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - __builtin_choose_expr vs. ?:, not a constant expression for _Static_assert"
href="https://bugs.llvm.org/show_bug.cgi?id=36033">36033</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__builtin_choose_expr vs. ?:, not a constant expression for _Static_assert
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>other
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>oliver.kleinke@c-01a.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19718" name="attach_19718" title="example program code">attachment 19718</a> <a href="attachment.cgi?id=19718&action=edit" title="example program code">[details]</a></span>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>