This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/69035] New: [constexpr] Using bultins sometimes make the expression non-constant
- From: "wielkiegie at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 23 Dec 2015 18:20:54 +0000
- Subject: [Bug c++/69035] New: [constexpr] Using bultins sometimes make the expression non-constant
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69035
Bug ID: 69035
Summary: [constexpr] Using bultins sometimes make the
expression non-constant
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: wielkiegie at gmail dot com
Target Milestone: ---
Hello,
I have a problem when using builtins (like __builtin_clz()) inside constexpr
functions.
Example:
constexpr int foo(int x) { return __builtin_clz(x); }
Using foo(<constant>) as a constant-expression results in the following error:
char tab[foo(1)];
// error: size of array âtabâ is not an integral constant-expression
However, if I add something to the foo(1) (and this something is not zero) it
starts to work:
char tab[foo(1)+1];
// no error.
Using __builtin_clz() directly also works:
char tab[__builtin_clz(1)];
// no error.
As does adding 1 inside foo():
constexpr int foo2(int x) { return __builtin_clz(x) + 1; }
char tab[foo(1)];
// no error.
The clang compiler does not produce these errors and works with every example
provided here.