http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52282
Bug #: 52282
Summary: [C++0x] ICE / confused by earlier errors with
decltype/constexpr
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
The following code causes the compiler problems. The version I am using is gcc
4.7.0-20120210.
template <typename T, T V>
struct A
{
static constexpr T a() { return V; }
};
template <typename T, T V>
struct B
{
typedef T type;
static constexpr type b() { return V; }
};
template <typename T, T V>
struct C
{
static constexpr decltype(V) c() { return V; }
};
static_assert(A<int, 10>::a() == 10, "oops");
static_assert(B<int, 10>::b() == 10, "oops");
static_assert(C<int, 10>::c() == 10, "oops");
struct D
{
static constexpr int d() { return 10; }
};
static_assert((A<int(*)(), &D::d>::a())() == 10, "oops");
static_assert((B<int(*)(), &D::d>::b())() == 10, "oops"); // line 30
static_assert((C<int(*)(), &D::d>::c())() == 10, "oops");
The code as given above will give the following output:
1.cpp:30:1: error: non-constant condition for static assertion
1.cpp:30:38: error: expression ‘D::d’ does not designate a constexpr function
1.cpp:17: confused by earlier errors, bailing out
Commenting out the line 30 will produce an ICE instead:
1.cpp: In instantiation of ‘struct C<int (*)(), D::d>’:
1.cpp:31:34: required from here
1.cpp:17:31: internal compiler error: in finish_decltype_type, at
cp/semantics.c:5277
There are two issues here: the first is, of course, the ICE; the second is that
gcc is not correctly determining the return type when it is abstracted as in
structs B and C and the type is a static function pointer.
Note that non-static member function pointers do not generate either issues,
although it is necessary to add "const" to the pointer type but not to the
corresponding function definition:
struct E
{
constexpr int e() { return 10; }
};
constexpr E e;
static_assert((e.*A<int(E::*)()const, &E::e>::a())() == 10, "oops");
static_assert((e.*B<int(E::*)()const, &E::e>::b())() == 10, "oops");
static_assert((e.*C<int(E::*)()const, &E::e>::c())() == 10, "oops");