From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3151 invoked by alias); 24 Dec 2012 14:23:14 -0000 Received: (qmail 3121 invoked by uid 22791); 24 Dec 2012 14:23:11 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Dec 2012 14:23:04 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBOEN4Ld002723 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 Dec 2012 09:23:04 -0500 Received: from localhost (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBOEN2OL006037 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 24 Dec 2012 09:23:03 -0500 Received: by localhost (Postfix, from userid 1000) id 5A8059F181; Mon, 24 Dec 2012 15:23:01 +0100 (CET) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] PR c++/55311 - Cannot specialize alias template with arg of type array of char References: <87sj6yhy4y.fsf@redhat.com> <50D7E162.5090309@redhat.com> X-URL: http://www.redhat.com Date: Mon, 24 Dec 2012 14:23:00 -0000 In-Reply-To: <50D7E162.5090309@redhat.com> (Jason Merrill's message of "Mon, 24 Dec 2012 00:00:18 -0500") Message-ID: <87mwx3fs1n.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-12/txt/msg01389.txt.bz2 Jason Merrill writes: > On 12/22/2012 11:03 AM, Dodji Seketeli wrote: >> [1]: The relacement of the VAR_DECL by its initializer is done by >> decay_conversion by callig decl_constant_value_safe. That replacement >> doesn't happen if processing_template_decl is not set. That's why it >> doesn't happen for the class template instantiation at line 9, leading >> to no error message there. > > This is the bug. decay_conversion on an array should take the > address, not return the initializer. Right. So would something like this be acceptable then? 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. --- gcc/cp/typeck.c | 20 +++++++++++++------- gcc/testsuite/g++.dg/cpp0x/alias-decl-30.C | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-30.C diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index ef76dcd..3fa913d 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1880,19 +1880,25 @@ decay_conversion (tree exp, tsubst_flags_t complain) return error_mark_node; } - /* FIXME remove? at least need to remember that this isn't really a - constant expression if EXP isn't decl_constant_var_p, like with - C_MAYBE_CONST_EXPR. */ - exp = decl_constant_value_safe (exp); - if (error_operand_p (exp)) - return error_mark_node; + code = TREE_CODE (type); + + /* For and array decl decay_conversion should not try to return its + initializer. */ + if (code != ARRAY_TYPE) + { + /* FIXME remove? at least need to remember that this isn't really a + constant expression if EXP isn't decl_constant_var_p, like with + C_MAYBE_CONST_EXPR. */ + exp = decl_constant_value_safe (exp); + if (error_operand_p (exp)) + return error_mark_node; + } if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp)) return nullptr_node; /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */ - code = TREE_CODE (type); if (code == VOID_TYPE) { if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-30.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-30.C new file mode 100644 index 0000000..7ad5e6d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-30.C @@ -0,0 +1,15 @@ +// Origin PR c++/55311 +// { dg-do compile { target c++11 } } + +template +struct A +{}; + +struct B {}; + +extern constexpr char HELLO_WORLD[] = "hello world"; + +A g; // <-- This works fine + +template +using PartiallySpecialized = A; // <-- This fails -- Dodji