http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52966
Bug #: 52966
Summary: ill-formed template constexpr functions are accepted?
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
The following code successfully compiles on g++ 4.7.0 with -std=c++11. I'm not
a language lawyer, but it seems like it shouldn't since the A::two() function
breaks the constexpr rules, either at template definition or template
instantiation time.
------
template<class T>
struct A {
static int two_nonconst() { return 2; }
static constexpr int two() { return two_nonconst(); }
}
constexpr int two() {
return A<int>::two();
}
------
There is no error message until you actually try to use the two() function in
an appropriate context, which could be very confusing.
------
int x[two()];
------
error: size of array 'x' is not an integral constant-expression