This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/53972] New: array constant expression expression not valid as template argument


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]