This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/65656] New: __builtin_constant_p should be constexpr
- From: "scovich at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 01 Apr 2015 18:52:28 +0000
- Subject: [Bug c++/65656] New: __builtin_constant_p should be constexpr
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65656
Bug ID: 65656
Summary: __builtin_constant_p should be constexpr
Product: gcc
Version: 4.8.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: scovich at gmail dot com
Consider the following program compiled with `gcc -std=c++11'
===== bug.cpp =====
#include <cstdio>
int main(int argc, char *argv[]) {
constexpr bool x = __builtin_constant_p(argc);
std::printf("x=%d\n", x);
}
===================
With optimizations disabled, it correctly treats __builtin_constant_p() as
constexpr and prints "0" as expected (because the value of argc is not a
compile-time constant).
With optimizations enabled (-O1 or higher), compilation fails:
bug.cpp: In function âint main(int, char**)â:
bug.cpp:3:48: error: âargcâ is not a constant expression
constexpr bool x = __builtin_constant_p(argc);
^
Clang 3.4 handles the case just fine.
While I can 100% understand that the return value of __builtin_constant_p()
might change depending on what information the optimizer has available, I'm
pretty sure __builtin_constant_p() should always return a value computable at
compile time.
NOTE: this issue is *NOT* the same as Bug #54021, in spite of the two sharing
the same title. The latter is mis-named: It actually requests support for
constant folding for ternary expressions involving __builtin_constant_p, even
when optimizations are disabled and such folding would not normally occur.