From patchwork Sun Jun 23 11:58:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1120788 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-503524-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="aq96iWUr"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="AbLb824z"; dkim-atps=neutral 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 45WrYZ5YPtz9s3C for ; Sun, 23 Jun 2019 21:58: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=ulbDvs2pvK8YvBbUrdbEu1sAufblnhtIAR+tzWcaunrCrg5tDZ 69cgxE7sQfFo0K5Zwt9RE1S0Z74G2jSO99jgOvPXsC+cjMCNjw3v/gMgPDBX1f9L uXuD6ndDTnmYwClnxqfc2PgDg/KvnY/fLFFs3MDNKUZn8XYr9/uQNJY6w= 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=2VurQ7yCaVtqI/JXL+e2TN87xU4=; b=aq96iWUry/S3Ouolyi1P mXR3bMPcYzzEOQxthLy8HTtlZ2YS3NY67F0zYu94xtKZW7WzsZGU5Va84RzLWTJv fisoNCnwWP6npI8+LFYJIb6jIwhI7j0JSz2BuVinWifQlZT/ajJR7hg4uw8Oqne0 RBa8Jzgbd+rX50OzYtannf0= Received: (qmail 16453 invoked by alias); 23 Jun 2019 11:58: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 16445 invoked by uid 89); 23 Jun 2019 11:58:49 -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=100, 7, 1007, declarator, 55 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; Sun, 23 Jun 2019 11:58:47 +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 x5NBsQcp146936; Sun, 23 Jun 2019 11:58:45 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=I9Mof4CL1799Ym4wk5kZ9cxYbPFJz63MdzgBngSLgk4=; b=AbLb824zABVtlOjzCsoveOeZzrxbUxZ3SeaRmz7bmwPKmOSHA3jgs5JBsckY3Jc67PVi yo23MbxJk0TTiJeTyZJXM5Tj3cPgia/BmyxOoEQ5ZXQ5LkzQWf53nOnhEwqGvhd/BVs0 eDfNf02k98pvnnRN8hYC6S3co9WwSlvXwhmSjY0BOOJfC4qw222Qv203NhR+6h4eZC4Z gNqhpo7sAVtOXfQFN0bqSuqV+QnshC6ZADltQpbQcHcFfybtBiP84h2qU6HSm1Kiz0Th nUciUwjWaXx6kbsLz81HfVWHRF5h/WFZhqykaIIV82f12fRKBxbKI0YfUza8WkMJcPQO /A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2t9cyq2jsp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 23 Jun 2019 11:58:44 +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 x5NBwdfQ194155; Sun, 23 Jun 2019 11:58:44 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2t9p6t6vy6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 23 Jun 2019 11:58:44 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5NBwh0J031492; Sun, 23 Jun 2019 11:58:43 GMT Received: from [192.168.1.4] (/87.13.236.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 23 Jun 2019 04:58:42 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] A few additional location improvements to grokdeclarator and check_tag_decl Message-ID: <75c69855-965c-6c03-fe95-905af5d15cc0@oracle.com> Date: Sun, 23 Jun 2019 13:58:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, here there are a couple of rather straightforward improvements in the second half of grokdeclarator plus a check_tag_decl change consistent with the other existing case of multiple_types_p diagnostic. Tested x86_64-linux. Thanks, Paolo. ///////////////////// /cp 2019-06-23 Paolo Carlini * decl.c (get_type_quals): New. (check_tag_decl): Use smallest_type_location and the latter in error_at about multiple types in one declaration. (grokdeclarator): Use locations[ds_storage_class] in error_at about static cdtor; use id_loc in error_at about flexible array member in union; use get_type_quals. /testsuite 2019-06-23 Paolo Carlini * g++.dg/diagnostic/static-cdtor-1.C: New. * g++.dg/cpp1z/has-unique-obj-representations2.C: Test location too. * g++.dg/other/anon-union3.C: Adjust expected location. * g++.dg/parse/error8.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 272584) +++ cp/decl.c (working copy) @@ -100,6 +100,7 @@ static tree build_cp_library_fn (tree, enum tree_c static void store_parm_decls (tree); static void initialize_local_var (tree, tree); static void expand_static_init (tree, tree); +static location_t smallest_type_location (int, const location_t*); /* The following symbols are subsumed in the cp_global_trees array, and listed here individually for documentation purposes. @@ -4802,6 +4803,24 @@ warn_misplaced_attr_for_class_type (location_t loc class_type, class_key_or_enum_as_string (class_type)); } +/* Returns the cv-qualifiers that apply to the type specified + by the DECLSPECS. */ + +static int +get_type_quals (const cp_decl_specifier_seq *declspecs) +{ + int type_quals = TYPE_UNQUALIFIED; + + if (decl_spec_seq_has_spec_p (declspecs, ds_const)) + type_quals |= TYPE_QUAL_CONST; + if (decl_spec_seq_has_spec_p (declspecs, ds_volatile)) + type_quals |= TYPE_QUAL_VOLATILE; + if (decl_spec_seq_has_spec_p (declspecs, ds_restrict)) + type_quals |= TYPE_QUAL_RESTRICT; + + return type_quals; +} + /* Make sure that a declaration with no declarator is well-formed, i.e. just declares a tagged type or anonymous union. @@ -4821,7 +4840,9 @@ check_tag_decl (cp_decl_specifier_seq *declspecs, bool error_p = false; if (declspecs->multiple_types_p) - error ("multiple types in one declaration"); + error_at (smallest_type_location (get_type_quals (declspecs), + declspecs->locations), + "multiple types in one declaration"); else if (declspecs->redefined_builtin_type) { if (!in_system_header_at (input_location)) @@ -10403,7 +10424,7 @@ grokdeclarator (const cp_declarator *declarator, a member function. */ cp_ref_qualifier rqual = REF_QUAL_NONE; /* cv-qualifiers that apply to the type specified by the DECLSPECS. */ - int type_quals = TYPE_UNQUALIFIED; + int type_quals = get_type_quals (declspecs); tree raises = NULL_TREE; int template_count = 0; tree returned_attrs = NULL_TREE; @@ -10449,13 +10470,6 @@ grokdeclarator (const cp_declarator *declarator, if (concept_p) constexpr_p = true; - if (decl_spec_seq_has_spec_p (declspecs, ds_const)) - type_quals |= TYPE_QUAL_CONST; - if (decl_spec_seq_has_spec_p (declspecs, ds_volatile)) - type_quals |= TYPE_QUAL_VOLATILE; - if (decl_spec_seq_has_spec_p (declspecs, ds_restrict)) - type_quals |= TYPE_QUAL_RESTRICT; - if (decl_context == FUNCDEF) funcdef_flag = true, decl_context = NORMAL; else if (decl_context == MEMFUNCDEF) @@ -11571,9 +11585,12 @@ grokdeclarator (const cp_declarator *declarator, virtual. A constructor may not be static. A constructor may not be declared with ref-qualifier. */ if (staticp == 2) - error ((flags == DTOR_FLAG) - ? G_("destructor cannot be static member function") - : G_("constructor cannot be static member function")); + error_at (declspecs->locations[ds_storage_class], + (flags == DTOR_FLAG) + ? G_("destructor cannot be static member " + "function") + : G_("constructor cannot be static member " + "function")); if (memfn_quals) { error ((flags == DTOR_FLAG) @@ -12431,7 +12448,7 @@ grokdeclarator (const cp_declarator *declarator, && (TREE_CODE (ctype) == UNION_TYPE || TREE_CODE (ctype) == QUAL_UNION_TYPE)) { - error ("flexible array member in union"); + error_at (id_loc, "flexible array member in union"); type = error_mark_node; } else Index: testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C =================================================================== --- testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C (revision 272583) +++ testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C (working copy) @@ -1,7 +1,7 @@ struct S; struct T { S t; }; // { dg-error "incomplete type" } struct U { int u[sizeof (S)]; }; // { dg-error "incomplete type" } -union V { char c; char d[]; }; // { dg-error "flexible array member in union" } +union V { char c; char d[]; }; // { dg-error "24:flexible array member in union" } bool a = __has_unique_object_representations (S); // { dg-error "incomplete type" } bool b = __has_unique_object_representations (T); bool c = __has_unique_object_representations (U); Index: testsuite/g++.dg/diagnostic/static-cdtor-1.C =================================================================== --- testsuite/g++.dg/diagnostic/static-cdtor-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/static-cdtor-1.C (working copy) @@ -0,0 +1,5 @@ +struct S +{ + static S(); // { dg-error "3:constructor" } + static ~S(); // { dg-error "3:destructor" } +}; Index: testsuite/g++.dg/other/anon-union3.C =================================================================== --- testsuite/g++.dg/other/anon-union3.C (revision 272583) +++ testsuite/g++.dg/other/anon-union3.C (working copy) @@ -3,9 +3,9 @@ class C { auto union // { dg-error "storage class" "" { target { ! c++11 } } } - { // { dg-error "auto" "" { target c++11 } .-1 } + { // { dg-error "auto|multiple types" "" { target c++11 } .-1 } int a; - }; // { dg-error "multiple types" "" { target c++11 } } + }; register union // { dg-error "storage class" } { int b; Index: testsuite/g++.dg/parse/error8.C =================================================================== --- testsuite/g++.dg/parse/error8.C (revision 272583) +++ testsuite/g++.dg/parse/error8.C (working copy) @@ -5,5 +5,5 @@ struct A { friend typename struct B; }; // { dg-error "28:expected nested-name-specifier before 'struct'" "expected" { target *-*-* } 4 } -// { dg-error "35:multiple types in one declaration" "multiple" { target *-*-* } 4 } +// { dg-error "19:multiple types in one declaration" "multiple" { target *-*-* } 4 } // { dg-error "12:friend declaration does not name a class or function" "friend decl" { target *-*-* } 4 }