From patchwork Mon Apr 8 14:41:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 234796 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id CAC212C00F9 for ; Tue, 9 Apr 2013 00:41:39 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=L9XVPyPiwOVA6AtBN qAQsBtArW7X0h2bRBPUU5s6TlXjuT4NhpSGLNik+UBjQeCcZpOOm2CNOxEGf5Yj6 Y62Jr3+v9y+dmh/lT9LHmX1OTclnD+gXKXS2/eiqhmYqJDkeKfWmHEHrRA7rGtB3 Ny906tncWcYSF3NrVv1VFgHDMI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=lxOGqjoQOarQW05qyeoxItu hxEY=; b=MZHfaS4mWnUd9Vs042r15m+jXD3LA5eH0zSa6qYDmYL2nErO4Sd8yUN q2+27xepQvfL1v9+A3DCveFK6YNlZX+uRn+FbwWVYZMO63tCMY/lqsNSyH51k4c2 12byArim1L0TRZz/YXBaY3UhBDNrBfbMKxE35DGhPiBij0xcwRcY= Received: (qmail 9087 invoked by alias); 8 Apr 2013 14:41:31 -0000 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 Received: (qmail 9073 invoked by uid 89); 8 Apr 2013 14:41:31 -0000 X-Spam-SWARE-Status: No, score=-6.2 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 08 Apr 2013 14:41:30 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r38EfRji006596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 8 Apr 2013 14:41:28 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r38EfQqp009029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 8 Apr 2013 14:41:27 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r38EfQqr018501; Mon, 8 Apr 2013 14:41:26 GMT Received: from [192.168.1.4] (/79.17.189.241) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 08 Apr 2013 07:41:26 -0700 Message-ID: <5162D714.3020507@oracle.com> Date: Mon, 08 Apr 2013 16:41:24 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: Re: [C++ Patch] PR 56871 References: <5162A0BA.5060302@oracle.com> In-Reply-To: <5162A0BA.5060302@oracle.com> X-Virus-Found: No ... I think that by the time we do the check, if old_decl is a FUNCTION_DECL we can safely assume that new_decl is also a FUNCTION_DECL, thus I can simplify the code. I'm finishing testing the below variant. Thanks Paolo. /////////////////////// Index: cp/decl.c =================================================================== --- cp/decl.c (revision 197572) +++ cp/decl.c (working copy) @@ -1196,12 +1196,21 @@ validate_constexpr_redeclaration (tree old_decl, t if (DECL_DECLARED_CONSTEXPR_P (old_decl) == DECL_DECLARED_CONSTEXPR_P (new_decl)) return true; - if (TREE_CODE (old_decl) == FUNCTION_DECL && DECL_BUILT_IN (old_decl)) + if (TREE_CODE (old_decl) == FUNCTION_DECL) { - /* Hide a built-in declaration. */ - DECL_DECLARED_CONSTEXPR_P (old_decl) - = DECL_DECLARED_CONSTEXPR_P (new_decl); - return true; + if (DECL_BUILT_IN (old_decl)) + { + /* Hide a built-in declaration. */ + DECL_DECLARED_CONSTEXPR_P (old_decl) + = DECL_DECLARED_CONSTEXPR_P (new_decl); + return true; + } + /* 7.1.5 [dcl.constexpr] + Note: An explicit specialization can differ from the template + declaration with respect to the constexpr specifier. */ + if (! DECL_TEMPLATE_SPECIALIZATION (old_decl) + && DECL_TEMPLATE_SPECIALIZATION (new_decl)) + return true; } error ("redeclaration %qD differs in %", new_decl); error ("from previous declaration %q+D", old_decl); Index: testsuite/g++.dg/cpp0x/constexpr-specialization.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-specialization.C (revision 0) +++ testsuite/g++.dg/cpp0x/constexpr-specialization.C (working copy) @@ -0,0 +1,12 @@ +// PR c++/56871 +// { dg-options "-std=c++11" } + +template constexpr int foo(T); +template<> int foo(int); +template<> int foo(int); // { dg-error "previous" } +template<> constexpr int foo(int); // { dg-error "redeclaration" } + +template int bar(T); +template<> constexpr int bar(int); +template<> constexpr int bar(int); // { dg-error "previous" } +template<> int bar(int); // { dg-error "redeclaration" }