https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61323

            Bug ID: 61323
           Summary: 'static' and 'const' attributes cause non-type
                    template argument matching failure
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bisqwit at iki dot fi

// Works:

char* table1[10];
template<unsigned size, char*(&table)[size]> void test1() { }
void tester1() { test1<10,table1>(); }

// Doesn't work:

static char* table2[10];
template<unsigned size, char*(&table)[size]> void test2() { }
void tester2() { test2<10,table2>(); } // error: 'table2' cannot appear in a
constant-expression

// Works:

const char* table3[10];
template<unsigned size, const char*(&table)[size]> void test3() { }
void tester3() { test3<10,table3>(); }

// Doesn't work:

const char* const table4[10] = {};
template<unsigned size, const char*const (&table)[size]> void test4() { }
void tester4() { test4<10,table4>(); } // error: 'table4' cannot appear in a
constant-expression

// Works:

const char* volatile table5[10] = {};
template<unsigned size, const char* volatile (&table)[size]> void test5() { }
void tester5() { test5<10,table5>(); }

// Doesn't work:

const char* const table6[10] = {};
template<unsigned size, const char*const (&table)[size]> void test6() { }
void tester6() { test6<10,table6>(); } // error: 'table6' cannot appear in a
constant-expression
--------------
Compiler versions tested:
  g++-4.4 (Debian 4.4.7-7) 4.4.7
  g++-4.5 (Debian 4.5.3-12) 4.5.3
  g++-4.6 (Debian 4.6.4-7) 4.6.4
  g++-4.7 (Debian 4.7.3-13) 4.7.3
  g++-4.8 (Debian 4.8.2-21) 4.8.2
  g++-4.9 (Debian 4.9.0-2) 4.9.0
Giving -std=c++11 did not make a difference.
--------------
Also tested: CLANG++ 3.5
CLANG++ gives diagnostic message: "non-type template argument referring to
object 'table2' with internal linkage is a C++11 extension" on all those cases
that GCC failed, when compiled without -std=c++11. Compiling with -std=c++11 or
even with -std=c++1y did not work on GCC.

Reply via email to