From patchwork Fri May 10 14:29:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1098083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-500448-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com 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 450t0C4ysHz9s7h for ; Sat, 11 May 2019 00:30:01 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=rKDUrCgp2+0+kuzzXuAa7j4mxruljIMRHa8YKHKAShuPVMeiKZ LOhLQVYnWyoBrMapFTSgMKGN2B57hePJAx/QjL0JH+OsX/m3NA99uGk5/8FI+SmI KlhThaUdG6eLDigTHA9oNVoDVb3Zqwaej/A2vvpuML0Q2g1BUj/Q/CKLc= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=RFKhzJMvF1Tm62rPvTxwrHGo2NM=; b=O6+x8dv1lq3hx5tcgdHI DeuYuppVaJVDrqKQa3IVslUTDaUEFQTqHaRlelOUiQ5nTLHNqkoKT37UClxiARsT hd+B5+kvj0odzOls9p8YuaYT3U3LrSBK4TXUxAv0L10PltlEUQfBYPoXUo7d/s8f oB5p2bxqZ6VEKDzCtFwgqwM= Received: (qmail 9766 invoked by alias); 10 May 2019 14:29:54 -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 9758 invoked by uid 89); 10 May 2019 14:29:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=H*r:Gateway, sk:paolo.c, U*paolo.carlini, sk:paoloc X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 May 2019 14:29:52 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x4AEOmAt143091; Fri, 10 May 2019 14:29:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=msHsWbyg2Qzo1BQKtNUdf5z0MX2xRywQ6GGJGhzRhwI=; b=sdyyIeXsDTEjKf+IdVFiO4dywpRRLcuPyVJGHLwYysBCKhc26zliNxNZQfcBJMpx/c2/ RvFD1ZsHjWSrs2BSN1EPTo9W6Z/m3VsJ2fMEMYyTmLUuNeMOQfEs4ThRfduZ43g6wLiq NLhT30v/iPOzkBetjjHlcP88C+OJtU3e46NS+YW7FS8uGQf+tt+eZdwj62GPzn9bmep4 qyeofQoaKeGhk61VrXUGP6twAC7v+S7joIJj7n0Po6lRcGvf179eP8SY5Tdeoo9II4hk JWhYPsc+0OXjdb/L5DCN+CbuYNFwchF3vQgIjTqt9O8tW2tJpWfptLtLp//zKiXsfILM Zw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2s94b19f7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 May 2019 14:29:50 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x4AETAVP122401; Fri, 10 May 2019 14:29:49 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2schw0eyg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 May 2019 14:29:49 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x4AETnaE011010; Fri, 10 May 2019 14:29:49 GMT Received: from [192.168.1.4] (/79.16.32.200) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 10 May 2019 07:29:48 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 89875 ("[7/8/9/10 Regression] invalid typeof reference to a member of an incomplete struct accepted at function scope") Message-ID: <7d7ad6b4-4877-98e0-9daa-a649089f12fa@oracle.com> Date: Fri, 10 May 2019 16:29:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, a while ago Martin noticed that an unintended consequence of an old tweak of mine - which avoided redundant error messages emitted from cp_parser_init_declarator - is that, in some cases, we started accepting ill-formed typeofs. Luckily, decltype isn't affected and that points to the real issue: by the time that place in cp_parser_init_declarator is reached, for a decltype version we already emitted a correct error message. Thus I think the right way to fix the problem is simply committing to tentative parse when, toward the end of cp_parser_sizeof_operand we know that we must be looking at a (possibly ill-formed) expression. Tested x86_64-linux. Thanks, Paolo. /////////////////////////// /cp 2019-05-10 Paolo Carlini PR c++/89875 * parser.c (cp_parser_sizeof_operand): When the type-id production did not work out commit to the tentative parse. /testsuite 2019-05-10 Paolo Carlini PR c++/89875 * g++.dg/cpp0x/decltype-pr66548.C: Remove xfail. * g++.dg/template/sizeof-template-argument.C: Adjust expected error. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 271059) +++ cp/parser.c (working copy) @@ -28998,7 +28998,11 @@ cp_parser_sizeof_operand (cp_parser* parser, enum /* If the type-id production did not work out, then we must be looking at the unary-expression production. */ if (!expr) - expr = cp_parser_unary_expression (parser); + { + cp_parser_commit_to_tentative_parse (parser); + + expr = cp_parser_unary_expression (parser); + } /* Go back to evaluating expressions. */ --cp_unevaluated_operand; Index: testsuite/g++.dg/cpp0x/decltype-pr66548.C =================================================================== --- testsuite/g++.dg/cpp0x/decltype-pr66548.C (revision 271059) +++ testsuite/g++.dg/cpp0x/decltype-pr66548.C (working copy) @@ -11,7 +11,7 @@ struct Meow {}; void f () { - decltype (Meow.purr ()) d; // { dg-error "expected primary-expression" "pr89875" { xfail c++98_only } } + decltype (Meow.purr ()) d; // { dg-error "expected primary-expression" } (void)&d; } Index: testsuite/g++.dg/template/sizeof-template-argument.C =================================================================== --- testsuite/g++.dg/template/sizeof-template-argument.C (revision 271059) +++ testsuite/g++.dg/template/sizeof-template-argument.C (working copy) @@ -3,9 +3,9 @@ template struct A {}; -template struct B : A {}; /* { dg-error "template argument" } */ +template struct B : A {}; /* { dg-error "expected primary-expression" } */ -template struct C : A {}; /* { dg-error "template argument" } */ +template struct C : A {}; /* { dg-error "expected primary-expression" } */ int a;