From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18294 invoked by alias); 7 Jan 2013 08:07:10 -0000 Received: (qmail 18195 invoked by uid 55); 7 Jan 2013 08:06:54 -0000 From: "dodji at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55311] Cannot specialize template parameter of type 'const char *const' in 'using' alias Date: Mon, 07 Jan 2013 08:07:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: dodji at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dodji at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg00442.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D55311 --- Comment #4 from Dodji Seketeli 2013-01-07 08= :06:52 UTC --- Author: dodji Date: Mon Jan 7 08:06:46 2013 New Revision: 194961 URL: http://gcc.gnu.org/viewcvs?root=3Dgcc&view=3Drev&rev=3D194961 Log: PR c++/55311 - Cannot specialize alias template with arg of type array of c= har Consider this test case: 1 template 2 struct A 3 {}; 4 5 struct B {}; 6 7 extern constexpr char HELLO_WORLD[] =3D "hello world"; 8 9 A g; // <-- This works fine 10 11 template 12 using PartiallySpecialized =3D A; // <-- This fa= ils 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: =E2=80=98"hello world"=E2=80=99 is not a valid te= mplate argument of type =E2=80=98const char*=E2=80=99 because =E2=80=98"hello world"=E2=80=99 = is not a variable using PartiallySpecialized =3D A; // <-- 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 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 =3D ((TREE_CODE (expr) =3D=3D ADDR_EXPR) ? TREE_OPERAND (expr, 0) : expr); if (TREE_CODE (decl) !=3D 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. Added: trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-30.C Modified: trunk/gcc/cp/typeck.c trunk/gcc/testsuite/g++.dg/init/array21.C