From patchwork Mon Jun 10 10:36:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1113021 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-502680-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 45MqM21Lcbz9s4Y for ; Mon, 10 Jun 2019 20:36:56 +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=ksq86DLsdw0uMWWeUmrs+T7ZwFmiAzTgQtDRntYot3ka2SkPt5 ih31CmUX+H31yq74vTVcv/MK+EcATsj5Rczd6Z79o5rDKtVigubvUv20mfb0SACX looU7nmUBJRcmcoDxs9G7XHY3F1SunYxT6wU4q4phLBBa2r2FAwRD1Yps= 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=OI+e0QrUPmftw+UcfAVI6CCJXnc=; b=nSCPPEeS1FXIzqn5yQKO TklRkyroMej1JRAeOua/E60RPivubqofJKNFZIlMGAuUFAn5M/S6X0Cst8mBwqAP SgiVO53t+hNPyfXCXTWBFSTA23RJdscnTI/Akms8ctWgqk2pN76D5BUE1HnxrGpk qDs4B8vB1izy9dHhlF5+C5Y= Received: (qmail 81365 invoked by alias); 10 Jun 2019 10:36:49 -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 81354 invoked by uid 89); 10 Jun 2019 10:36:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 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=67, five X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Jun 2019 10:36:46 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5AASdXB089856; Mon, 10 Jun 2019 10:36:44 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=zzBzjrLo5xvKGevKGUfbIYNlbM8s0DkosdpNl+g3OX4=; b=P54HngD8+U06DHa1HTWXEmqDzHjRWqjxPQqH7BFfFHRWeIE4smvWTCkRFGCGV1etOJxB tnl+cY4I6qCO4I831d95e4uvGUNsFXY+qDYdNxiyO+Nip76I0MQJhN+Vb6aKiM6hu04a 5OoleBAvDgCAT44xEKc1XyjT12QxpiLnMhgwTbk+au9/N3eG/w5/h7vJtZGhBrb714UO fmJ+nCenJhDDLME3gbP3m3IA9NLEvKJMwm6Nkx/XI9y1R3mxMp/r+LFwLe8q6a5evtCC mlvkEuGmb6bvO7tZXoHMlbHDEJb1fpkYDSPraB/woXlP8MkasnUCFRcI77cNBIw6TBF1 tg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2t04ete411-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2019 10:36:44 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5AAai6i033176; Mon, 10 Jun 2019 10:36:44 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2t1jpgta95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2019 10:36:40 +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 x5AAabih025920; Mon, 10 Jun 2019 10:36:37 GMT Received: from [192.168.1.4] (/79.42.221.26) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 10 Jun 2019 03:36:36 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] More grokdeclarator locations fixes Message-ID: <814e2078-c135-56c8-201f-44ac9712dbc6@oracle.com> Date: Mon, 10 Jun 2019 12:36:34 +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, this one requires my last patch, uses id_loc in a few additional places in the last part of the function. Most of the changes should be straightforward, I only want to mention the "typedef name may not be a nested-name-specifier" change, where, not using input_location means that for a test like g++.old-deja/g++.jason/crash10.C: struct A {   enum foo { bar }; }; typedef A::foo A::foo; the location is under the 'A' of the second 'A::foo'. The EDG front-end does exactly the same; clang points to the 'f' but then has the wavy thing reaching back to 'A' (a while ago I already mentioned that we don't have that option). Tested x86_64-linux. Thanks, Paolo. ///////////////////// /cp 2019-06-10 Paolo Carlini * decl.c (grokdeclarator): Use id_loc in five additional places in the last part of the function. /testsuite 2019-06-10 Paolo Carlini * g++.dg/diagnostic/variably-modified-type-1.C: New. * g++.dg/cpp0x/alias-decl-1.C: Test the location too. * g++.dg/other/pr84792-1.C: Likewise. * g++.dg/other/pr84792-2.C: Likewise. * g++.dg/parse/error24.C: Likewise. * g++.dg/parse/error32.C: Likewise. * g++.dg/parse/error33.C: Likewise. * g++.dg/parse/saved1.C: Likewise. * g++.dg/template/operator6.C: Likewise. * g++.dg/template/pr61745.C: Likewise. * g++.dg/template/typedef41.C: Likewise. * g++.old-deja/g++.jason/crash10.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 272105) +++ cp/decl.c (working copy) @@ -12000,9 +12000,11 @@ grokdeclarator (const cp_declarator *declarator, && variably_modified_type_p (type, NULL_TREE)) { if (decl_context == FIELD) - error ("data member may not have variably modified type %qT", type); + error_at (id_loc, + "data member may not have variably modified type %qT", type); else - error ("parameter may not have variably modified type %qT", type); + error_at (id_loc, + "parameter may not have variably modified type %qT", type); type = error_mark_node; } @@ -12106,7 +12108,7 @@ grokdeclarator (const cp_declarator *declarator, if (id_declarator && declarator->u.id.qualifying_scope) { - error ("typedef name may not be a nested-name-specifier"); + error_at (id_loc, "typedef name may not be a nested-name-specifier"); type = error_mark_node; } @@ -12130,7 +12132,7 @@ grokdeclarator (const cp_declarator *declarator, } else if (current_class_type && constructor_name_p (unqualified_id, current_class_type)) - permerror (input_location, "ISO C++ forbids nested type %qD with same name " + permerror (id_loc, "ISO C++ forbids nested type %qD with same name " "as enclosing class", unqualified_id); @@ -12288,7 +12290,7 @@ grokdeclarator (const cp_declarator *declarator, /* Only functions may be declared using an operator-function-id. */ if (dname && IDENTIFIER_ANY_OP_P (dname)) { - error ("declaration of %qD as non-function", dname); + error_at (id_loc, "declaration of %qD as non-function", dname); return error_mark_node; } Index: testsuite/g++.dg/cpp0x/alias-decl-1.C =================================================================== --- testsuite/g++.dg/cpp0x/alias-decl-1.C (revision 272105) +++ testsuite/g++.dg/cpp0x/alias-decl-1.C (working copy) @@ -11,5 +11,6 @@ template using Ptr = U*; template struct Ptr {}; // { dg-error "specialization" } struct A { - using A = int;//{ dg-error "nested|has|same name as|class|in which|declared" } + using A = int; // { dg-error "11:ISO C\\+\\+ forbids nested type .A." } +// { dg-error "same name as" "" { target c++11 } .-1 } }; Index: testsuite/g++.dg/diagnostic/variably-modified-type-1.C =================================================================== --- testsuite/g++.dg/diagnostic/variably-modified-type-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/variably-modified-type-1.C (working copy) @@ -0,0 +1,12 @@ +// { dg-options "" } + +void foo () +{ + int n; + typedef int X[n]; + struct Z + { + X x __attribute__((unused)); // { dg-error "7:data member may not have variably modified type" } + void bar (X x __attribute__((unused))); // { dg-error "17:parameter may not have variably modified type" } + }; +} Index: testsuite/g++.dg/other/pr84792-1.C =================================================================== --- testsuite/g++.dg/other/pr84792-1.C (revision 272105) +++ testsuite/g++.dg/other/pr84792-1.C (working copy) @@ -3,4 +3,4 @@ struct A {}; typedef struct { virtual void foo() {} -} A::B; // { dg-error "typedef" } +} A::B; // { dg-error "3:typedef" } Index: testsuite/g++.dg/other/pr84792-2.C =================================================================== --- testsuite/g++.dg/other/pr84792-2.C (revision 272105) +++ testsuite/g++.dg/other/pr84792-2.C (working copy) @@ -3,4 +3,4 @@ struct A {}; typedef struct { void foo() {} -} A::B; // { dg-error "typedef" } +} A::B; // { dg-error "3:typedef" } Index: testsuite/g++.dg/parse/error24.C =================================================================== --- testsuite/g++.dg/parse/error24.C (revision 272105) +++ testsuite/g++.dg/parse/error24.C (working copy) @@ -2,7 +2,7 @@ // PR c++/19395 struct A { - typedef int ::X; // { dg-error "17:typedef name may not be a nested-name-specifier" } + typedef int ::X; // { dg-error "15:typedef name may not be a nested-name-specifier" } }; Index: testsuite/g++.dg/parse/error32.C =================================================================== --- testsuite/g++.dg/parse/error32.C (revision 272105) +++ testsuite/g++.dg/parse/error32.C (working copy) @@ -3,7 +3,7 @@ struct A {}; -typedef void (A::T)(); /* { dg-error "typedef name may not be a nested-name-specifier" } */ +typedef void (A::T)(); /* { dg-error "15:typedef name may not be a nested-name-specifier" } */ void foo() { Index: testsuite/g++.dg/parse/error33.C =================================================================== --- testsuite/g++.dg/parse/error33.C (revision 272105) +++ testsuite/g++.dg/parse/error33.C (working copy) @@ -6,7 +6,7 @@ struct A void foo(); }; -typedef void (A::T)(); /* { dg-error "typedef name may not be a nested" } */ +typedef void (A::T)(); /* { dg-error "15:typedef name may not be a nested" } */ void bar(T); /* { dg-message "note: declared here" } */ Index: testsuite/g++.dg/parse/saved1.C =================================================================== --- testsuite/g++.dg/parse/saved1.C (revision 272105) +++ testsuite/g++.dg/parse/saved1.C (working copy) @@ -1,6 +1,7 @@ // Test that the parser doesn't go into an infinite loop from ignoring the // PRE_PARSED_FUNCTION_DECL token. -class C { static void* operator new(size_t); }; // { dg-error "" } +class C { static void* operator new(size_t); }; // { dg-error "24:declaration of .operator new. as non-function" } +// { dg-error "expected|ISO C\\+\\+ forbids" "" { target *-*-* } .-1 } void* C::operator new(size_t) { return 0; } // { dg-error "" } class D { D(int i): integer(i){}}; // { dg-error "" } Index: testsuite/g++.dg/template/operator6.C =================================================================== --- testsuite/g++.dg/template/operator6.C (revision 272105) +++ testsuite/g++.dg/template/operator6.C (working copy) @@ -1,4 +1,4 @@ // PR c++/27315 // { dg-do compile } -template void operator+; // { dg-error "non-function" } +template void operator+; // { dg-error "15:declaration of .operator\\+. as non-function" } Index: testsuite/g++.dg/template/pr61745.C =================================================================== --- testsuite/g++.dg/template/pr61745.C (revision 272105) +++ testsuite/g++.dg/template/pr61745.C (working copy) @@ -20,5 +20,6 @@ class Zp { Zp operator-() const { return Zp(p-val); } // In C++2A, we have an unqualified-id (operator-) followed by // '<', and name lookup found a function. - friend Zp operator- <>(const Zp& a, const Zp& b); // { dg-error "declaration|expected" "" { target c++17_down } } + friend Zp operator- <>(const Zp& a, const Zp& b); // { dg-error "20:declaration of .operator\\-. as non-function" "" { target c++17_down } } + // { dg-error "expected" "" { target c++17_down } .-1 } }; Index: testsuite/g++.dg/template/typedef41.C =================================================================== --- testsuite/g++.dg/template/typedef41.C (revision 272105) +++ testsuite/g++.dg/template/typedef41.C (working copy) @@ -2,7 +2,7 @@ template struct A { - typedef int ::X; // { dg-error "" } + typedef int ::X; // { dg-error "15:typedef name" } }; A<0> a; Index: testsuite/g++.old-deja/g++.jason/crash10.C =================================================================== --- testsuite/g++.old-deja/g++.jason/crash10.C (revision 272105) +++ testsuite/g++.old-deja/g++.jason/crash10.C (working copy) @@ -5,4 +5,4 @@ struct A { enum foo { bar }; }; -typedef A::foo A::foo; // { dg-error "" } causes compiler segfault +typedef A::foo A::foo; // { dg-error "16:typedef name" } causes compiler segfault