[Bug c++/79083] New: GCC incorrectly compiles calls to constexpr static methods via a non-constexpr variable
matt at godbolt dot org
gcc-bugzilla@gcc.gnu.org
Fri Jan 13 14:26:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79083
Bug ID: 79083
Summary: GCC incorrectly compiles calls to constexpr static
methods via a non-constexpr variable
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: matt at godbolt dot org
Target Milestone: ---
Consider the following (unusual) code:
--
struct Foo { static constexpr bool hasBar() { return true; } };
void test(const Foo &f) {
static_assert(Foo::hasBar(), ""); // -is ok
static_assert(f.hasBar(), ""); // fails on clang trunk, works in GCC
}
--
GCC incorrectly compiles the second static assert; clang gives the error:
"static_assert expression is not an integral constant expression".
I initially thought this was a bug in clang, but according to Richard Smith
it's not: https://llvm.org/bugs/show_bug.cgi?id=31624 :
[expr.const]/2.10:
"[An expression is not a constant expression if it would evaluate] an
id-expression that refers to a variable or data member of reference type unless
the reference has a preceding initialization and either
— it is initialized with a constant expression or
— its lifetime began within the evaluation of e;"
Thus we believe GCC's behaviour is the incorrect in this case.
More information about the Gcc-bugs
mailing list