From patchwork Fri Mar 10 22:38:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 737598 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vg2Hc2nn3z9s7N for ; Sat, 11 Mar 2017 09:39:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="S1KC3X82"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=axu9t5EQTXBNtFIJ9 +DCeillTvFcsTpPGvrD6MWXBvAomxGp6OEzpFQTlNzg2TeyfI/OrB8+u2eemV2VU uRPgQDZBSK9J7Q6TgiW7AlcdjbCEkeQ6x1DA45rEcMbsQewtw+Y58issM8CzcdUT noK87h9jljla72amUh5f8MlwP8= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=6cWZolB8gd5pLBiqQETau27 KYOE=; b=S1KC3X82yAb90plwRCxdq+952usGXzw+mNxg7Sq6VohNlvBMCCXrEtk EVpXthpPKMEFA9/tLu1zUuPhxlYI0dFZjHmsk3a0FuRNzdkaC0Otjaty+qbhEBXU WraJPY5PnI2bVMkTWWkeH2Ws4DoOgnX9EQ4FTy4g95YFGcrIO/bg= Received: (qmail 114729 invoked by alias); 10 Mar 2017 22:39:00 -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 114703 invoked by uid 89); 10 Mar 2017 22:38:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_SORBS_SPAM, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=H*i:sk:oq3_Z8R, H*MI:sk:oq3_Z8R, H*f:sk:oq3_Z8R, H*i:sk:2m8DMC7 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Mar 2017 22:38:58 +0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v2AMcu3P016070 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Mar 2017 22:38:56 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v2AMctM9012280 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Mar 2017 22:38:55 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v2AMcsp1019200; Fri, 10 Mar 2017 22:38:55 GMT Received: from [192.168.1.4] (/79.12.220.1) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 10 Mar 2017 14:38:54 -0800 Subject: Re: [C++ Patch/RFC] PR 77752 To: Jason Merrill References: <673bd2d5-e060-8f2c-8c69-8139064fde45@oracle.com> Cc: "gcc-patches@gcc.gnu.org" From: Paolo Carlini Message-ID: <82a3fdf8-74ac-a15e-d1ef-b85782b6055f@oracle.com> Date: Fri, 10 Mar 2017 23:38:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes Hi, On 10/03/2017 16:57, Jason Merrill wrote: > On Fri, Mar 10, 2017 at 9:58 AM, Paolo Carlini wrote: >> As such, the broken declaration cannot be rejected by the code we have in >> finish_struct, something must happen earlier than that. It seems to me that >> xref_tag_1 can be a good place, per the below patchlet, which passes testing >> on x86_64-linux. I briefly wondered if making is_std_init_list stricter >> would make sense instead, but I don't think so (consistently with the trail >> of c++/60848 too): I believe that by the time we use is_std_init_list in the >> internals we want something as simple as possible, we are assuming that >> broken, fake, std::initializer_list aren't around in the translation unit. >> In terms of details, I also wondered if CLASSTYPE_IS_TEMPLATE would make for >> a better check, but seems unnecessarily more complex. Also, in principle, we >> may want to have an even stricter check at declaration time (how many >> template parameters, etc) but that seems overkilling and I don't think we >> are risking ICEs because of that. > I agree with all of this. How about in pushtag_1 instead, where we > can return error_mark_node instead of aborting? Sure. In that case the testcase for that older issue also requires adjusting. The below passes testing, anyway. Thanks, Paolo. //////////////////// Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 246023) +++ cp/name-lookup.c (working copy) @@ -6207,6 +6207,15 @@ pushtag_1 (tree name, tree type, tag_scope scope) decl = pushdecl_with_scope_1 (decl, b, /*is_friend=*/false); if (decl == error_mark_node) return decl; + + if (DECL_CONTEXT (decl) == std_node + && strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0 + && !CLASSTYPE_TEMPLATE_INFO (type)) + { + error ("declaration of std::initializer_list does not match " + "#include , isn't a template"); + return error_mark_node; + } } if (! in_class) Index: testsuite/g++.dg/cpp0x/initlist85.C =================================================================== --- testsuite/g++.dg/cpp0x/initlist85.C (revision 246023) +++ testsuite/g++.dg/cpp0x/initlist85.C (working copy) @@ -3,7 +3,7 @@ namespace std { - struct initializer_list {}; // { dg-message "initializer_list" } + struct initializer_list {}; // { dg-error "declaration" } } void foo(std::initializer_list &); @@ -10,7 +10,5 @@ void foo(std::initializer_list &); void f() { - foo({1, 2}); + foo({1, 2}); // { dg-error "invalid initialization" } } - -// { dg-prune-output "compilation terminated" } Index: testsuite/g++.dg/cpp0x/initlist97.C =================================================================== --- testsuite/g++.dg/cpp0x/initlist97.C (revision 0) +++ testsuite/g++.dg/cpp0x/initlist97.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/77752 +// { dg-do compile { target c++11 } } + +namespace std { + class initializer_list; // { dg-error "declaration" } +} +void f(std::initializer_list l) { f({2}); } // { dg-error "incomplete type" }