This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53972] New: array constant expression expression not valid as template argument
- From: "fw at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 15 Jul 2012 13:25:27 +0000
- Subject: [Bug c++/53972] New: array constant expression expression not valid as template argument
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53972
Bug #: 53972
Summary: array constant expression expression not valid as
template argument
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: fw@gcc.gnu.org
Instantiating sub1 failes with:
bug.cc:10:24: error: âarrayâ is not a constant expression
return Constify<array[I]>::value;
This is inconsistent because sub2 shows that the array subscript is recognized
as a constant expression in other context.
template <unsigned I>
struct Constify {
enum { value = I };
};
template <unsigned N>
constexpr char
sub1(const char (&array)[N], unsigned I)
{
return Constify<array[I]>::value;
}
template <unsigned N>
constexpr char
sub2(const char (&array)[N], unsigned I)
{
return array[I];
}
int
main()
{
sub1("foo", 2);
enum {
value = sub2("foo", 2)
};
Constify<value>::value;
}