diff options
author | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-01-07 08:06:46 +0000 |
---|---|---|
committer | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-01-07 08:06:46 +0000 |
commit | 00e5e80956c4c855ef0ff178ac5b680567851a8c (patch) | |
tree | 93908fdd901e2fcf0b9ab2e350080821a3fb529a /gcc/fortran | |
parent | aa8bfe5df93737d1c46bc234369f664afa75ee8e (diff) | |
download | gcc-00e5e80956c4c855ef0ff178ac5b680567851a8c.tar.gz |
PR c++/55311 - Cannot specialize alias template with arg of type array of char
Consider this test case:
1 template <const char *const C, typename T>
2 struct A
3 {};
4
5 struct B {};
6
7 extern constexpr char HELLO_WORLD[] = "hello world";
8
9 A<HELLO_WORLD, B> g; // <-- This works fine
10
11 template <typename T>
12 using PartiallySpecialized = A<HELLO_WORLD, T>; // <-- This fails
13
At line 12 G++ fails to instantiate the alias template that has a
string variable initialized with a string literal, with the error
message:
test.cc:12:46: error: ‘"hello world"’ is not a valid template argument of type ‘const char*’ because ‘"hello world"’ is not a variable
using PartiallySpecialized = A<HELLO_WORLD, T>; // <-- This fails
^
Note that instantiating the template A at line 9 with the same
arguments as in the problematic case above works.
This happens in the context of lookup_template_class_1, when it handles
the alias template instantiation A<HELLO_WORLD, T> and thus passes the
VAR_DECL for HELLO_WORLD to convert_nontype_argument.
Note that from there decay_conversion replaces the the VAR_DECL with
its STRING_CST initializer[1]. Latter on, convert_nontype_argument
checks that the HELLO_WORLD constant it received as argument was
indeed a VAR_DECL:
else
{
tree decl;
decl = ((TREE_CODE (expr) == ADDR_EXPR)
? TREE_OPERAND (expr, 0) : expr);
if (TREE_CODE (decl) != VAR_DECL)
{
error ("%qE is not a valid template argument of type %qT "
"because %qE is not a variable",
expr, type, decl);
return NULL_TREE;
}
But the issue is, that VAR_DECL has been replaced by STRING_CST, so
the last 'if' above fails.
The fix is to teach decay_conversion to return the address of array,
rather than returning its initializer.
Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.
gcc/cp/
PR c++/55311
* pt.c (decay_conversion): Do not return the initializer of an array.
gcc/testsuite/
PR c++/55311
* g++.dg/cpp0x/alias-decl-30.C: New test.
* g++.dg/init/array21.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194961 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran')
0 files changed, 0 insertions, 0 deletions