[Bug c++/65695] New: [4.9/5 Regression] calling constexpr constructor with pointer-to-member is not a constant expression
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Apr 8 10:59:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65695
Bug ID: 65695
Summary: [4.9/5 Regression] calling constexpr constructor with
pointer-to-member is not a constant expression
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
From https://gcc.gnu.org/ml/gcc-help/2015-04/msg00034.html
template <typename T>
struct Bar
{
using MemberFuncT = int (T::*)();
MemberFuncT h_;
constexpr Bar(MemberFuncT h) : h_{h}
{
}
};
struct Foo
{
int test()
{
return -1;
}
// this causes the brace-enclosed initializer error message:
static constexpr Bar<Foo> bar = Bar<Foo>(&Foo::test);
// but this line does not:
// static constexpr Bar<Foo> bar = Bar<Foo>(nullptr);
// this line also causes the error message, unless you remove the
// explict constructor in Bar.
// static constexpr Bar<Foo> bar = {&Foo::test};
};
constexpr Bar<Foo> Foo::bar;
// the line below does not cause any problems, either:
// static constexpr Bar<Foo> bar = Bar<Foo>(&Foo::test);
int main(void)
{
Foo f;
return (f.*(Foo::bar.h_))();
}
c.cc:20:56: error: ‘Bar<Foo>{&Foo::test}’ is not a constant expression
static constexpr Bar<Foo> bar = Bar<Foo>(&Foo::test);
^
Clang and EDG accept the code.
More information about the Gcc-bugs
mailing list