From patchwork Mon Dec 24 14:23:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 208082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BADC62C007E for ; Tue, 25 Dec 2012 01:23:26 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1356963807; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=QCiY6tNw+MoTrTAcySNBhpKXOo0=; b=xvup8i2QSpVMcOUNZgTDi1u+4hOJFz8TuhzojBddmmJLU5/OJ5Xu8Nzx3akeSR IecNQIhVKqTy+eJb+CYgNYzNKjWfsHndnKuPPg6MzBQxkjjxxGTzHzl2+iwYegK/ ubcoczv32qaoeeMQLmw80AyN6h4Iog03DFJU5q5QdgLhI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=miflFYEkwzNIl24rQkjgQVh0qQZ7UOEUdmq8QuiP7vHMLdA30G5xokfjVZB+F4 iOmRixwHdJ2nxa+7tQyFZRuvXO/fco9U16Zno9ojFe/4jN/QfXyz8TSVMfvNwkA5 nvSIxwXRw54P6u//opsZfKXkCn/KH8CLgxKOcWyhVIYHM=; 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 15:23:00 +0100 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 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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