public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dodji at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-55311-4-R9ScM6eQcq@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-55311-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55311 --- Comment #4 from Dodji Seketeli <dodji at gcc dot gnu.org> 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=gcc&view=rev&rev=194961 Log: 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. 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
next prev parent reply other threads:[~2013-01-07 8:07 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-11-13 14:16 [Bug c++/55311] New: " niels at penneman dot org 2012-12-04 21:01 ` [Bug c++/55311] " niels at penneman dot org 2012-12-05 8:33 ` niels at penneman dot org 2012-12-22 16:09 ` dodji at seketeli dot org 2012-12-22 16:11 ` dodji at gcc dot gnu.org 2013-01-07 8:07 ` dodji at gcc dot gnu.org [this message] 2013-01-07 11:00 ` dodji at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-55311-4-R9ScM6eQcq@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).