https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124214
Bug ID: 124214
Summary: Templated class with static constexpr method compiles
without warning about non C++11 compliant body
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: giovanni.gaio at proton dot me
Target Milestone: ---
Consider the following:
template< typename T = int >
class foo {
public:
static constexpr int bar(T x){
(void) x;
return 42;
}
};
int f(int x){
return foo<>::bar( x );
}
This is NOT valid C++11 as the constexpr function contains a return statement
and a non-null statement. So compiling with -std=c++11 should raise an error
but doesn't.
Live demonstration: https://godbolt.org/z/8n6PPvoP8
An error is correctly raised with GCC11.5, but not later versions