From patchwork Tue Jan 15 16:58:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1025324 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-494087-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="LJPch1/j"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="UI8cRb9B"; 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 43fGks3kZTz9sCs for ; Wed, 16 Jan 2019 03:58:44 +1100 (AEDT) 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=IROTrmDbm92k1ZZj/ApL5rEmfxmon/UNYDH9Wz1l0fLH8IGBIP /fIMlmF0Y0rrAITqwxygI0E1pHL4p+99iV7vnofA9V3bko0WrjVtzIPodXRhVN2p M1iC4HWjcIJK3IXJMwW62AK01RPZkyNG8mrG8/ZmWv558CkPI80cjy7Bs= 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=fnMCbpSA42l+rQ9JgYvelcW/VeM=; b=LJPch1/jDJMiIGcZOgHL j09TF3XqNU256WMU+LBANd9ukqRWj/dP3+RZNarNqtaXKvz0mfAH1ppSLUu4WRYm Na0TsSyMgRq/MGnWKN7fr+xFCSvUYRRuhZb5tDmBAtG2cEOLwgvKLNllIZmAAIXN diDHV10yB9pWx3tZi0lwaj8= Received: (qmail 116801 invoked by alias); 15 Jan 2019 16:58:37 -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 116790 invoked by uid 89); 15 Jan 2019 16:58:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=friend 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; Tue, 15 Jan 2019 16:58:33 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0FGnREp194900; Tue, 15 Jan 2019 16:58:32 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=MsFM0mdL+9wVtTqQlIRJq5YyU8ath+D+NeU2/IRnPKM=; b=UI8cRb9BS5IR/8F8BeTzN6bY6ea7Vp7V9FlcbRlwLXamBmRATcmsvB3Koee9pkzmtzCE YrEcrTjNBrb8VrCkIbgJJlJ5FxrkH6BYu/0jhQMahHbjoYrCVG34SgPyqueEt6+J8SEs syhtDY4HwDeleEBEkc3B7FU4PiD/18KKiMHx3j/5OTwofsNDn8A9rFpTT5yh2lH0leaK dbvSToTUygTN6TVav1HfJuFZYaEz1H93tyQK8rMRN1995miYtq25iP6nuhjC2NiHXuCl C19i3dl64QPWl2HPKNdhwj8LBWMU72zqBfawAlKManspCn2oIxDefS8yghWSBgbzjRGZ Eg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2pybjs52yt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Jan 2019 16:58:31 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0FGwV1I028114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Jan 2019 16:58:31 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0FGwVak020448; Tue, 15 Jan 2019 16:58:31 GMT Received: from [192.168.1.4] (/79.19.31.237) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Jan 2019 08:58:30 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable Message-ID: Date: Tue, 15 Jan 2019 17:58:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, something a little different from my last patches but nevertheless pretty straightforward (noticed while I was wondering whether we should immediately move the location_t grokdeclarator local even further up). Tested x86_64-linux, as usual. Thanks, Paolo. /////////////////////// /cp 2019-01-15 Paolo Carlini * decl.c (grokdeclarator): Use locations[ds_storage_class] in error messages about ill-formed uses of mutable. /testsuite 2019-01-15 Paolo Carlini * g++.dg/other/pr33558.C: Test location too. * g++.dg/other/pr33558-2.C: Likewise. * g++.dg/parse/crash4.C: Likewise. * g++.old-deja/g++.brendan/err-msg11.C: Likewise. * g++.old-deja/g++.mike/p7635.C: Likewise. * g++.old-deja/g++.other/decl6.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 267932) +++ cp/decl.c (working copy) @@ -11902,36 +11902,40 @@ grokdeclarator (const cp_declarator *declarator, if (storage_class == sc_mutable) { + location_t sloc = declspecs->locations[ds_storage_class]; if (decl_context != FIELD || friendp) { - error ("non-member %qs cannot be declared %", name); + error_at (sloc, "non-member %qs cannot be declared %", + name); storage_class = sc_none; } else if (decl_context == TYPENAME || typedef_p) { - error ("non-object member %qs cannot be declared %", name); + error_at (sloc, + "non-object member %qs cannot be declared %", + name); storage_class = sc_none; } else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) { - error ("function %qs cannot be declared %", name); + error_at (sloc, "function %qs cannot be declared %", name); storage_class = sc_none; } else if (staticp) { - error ("static %qs cannot be declared %", name); + error_at (sloc, "static %qs cannot be declared %", name); storage_class = sc_none; } else if (type_quals & TYPE_QUAL_CONST) { - error ("const %qs cannot be declared %", name); + error_at (sloc, "const %qs cannot be declared %", name); storage_class = sc_none; } else if (TYPE_REF_P (type)) { - permerror (input_location, "reference %qs cannot be declared " - "%", name); + permerror (sloc, "reference %qs cannot be declared %", + name); storage_class = sc_none; } } Index: testsuite/g++.dg/other/pr33558-2.C =================================================================== --- testsuite/g++.dg/other/pr33558-2.C (revision 267931) +++ testsuite/g++.dg/other/pr33558-2.C (working copy) @@ -2,5 +2,5 @@ /* { dg-options "-fpermissive" } */ class X { - mutable int &q; /* { dg-warning "cannot be declared 'mutable'" } */ + mutable int &q; /* { dg-warning "3:reference .q. cannot be declared .mutable." } */ }; Index: testsuite/g++.dg/other/pr33558.C =================================================================== --- testsuite/g++.dg/other/pr33558.C (revision 267931) +++ testsuite/g++.dg/other/pr33558.C (working copy) @@ -1,5 +1,5 @@ /* { dg-do compile } */ class X { - mutable int &q; /* { dg-error "cannot be declared 'mutable'" } */ + mutable int &q; /* { dg-error "3:reference .q. cannot be declared .mutable." } */ }; Index: testsuite/g++.dg/parse/crash4.C =================================================================== --- testsuite/g++.dg/parse/crash4.C (revision 267931) +++ testsuite/g++.dg/parse/crash4.C (working copy) @@ -7,6 +7,6 @@ struct Bar { void func(void) { - mutable Bar::type x; // { dg-error "" } + mutable Bar::type x; // { dg-error "8:non-member .x. cannot be declared .mutable." } } }; Index: testsuite/g++.old-deja/g++.brendan/err-msg11.C =================================================================== --- testsuite/g++.old-deja/g++.brendan/err-msg11.C (revision 267931) +++ testsuite/g++.old-deja/g++.brendan/err-msg11.C (working copy) @@ -1,3 +1,3 @@ // { dg-do assemble } // GROUPS passed error-messages -void foo (mutable int x);// { dg-error "" } non-member `x' cannot be declared `mutable'.* +void foo (mutable int x);// { dg-error "11:non-member .x. cannot be declared .mutable." } non-member `x' cannot be declared `mutable'.* Index: testsuite/g++.old-deja/g++.mike/p7635.C =================================================================== --- testsuite/g++.old-deja/g++.mike/p7635.C (revision 267931) +++ testsuite/g++.old-deja/g++.mike/p7635.C (working copy) @@ -3,5 +3,5 @@ class DaycountBasis { mutable const int * p; - mutable int * const q; // { dg-error "" } + mutable int * const q; // { dg-error "3:const .q. cannot be declared .mutable." } }; Index: testsuite/g++.old-deja/g++.other/decl6.C =================================================================== --- testsuite/g++.old-deja/g++.other/decl6.C (revision 267931) +++ testsuite/g++.old-deja/g++.other/decl6.C (working copy) @@ -11,16 +11,16 @@ struct A friend explicit B::B (); // { dg-error "" } only ctor decls can be explicit int f(const); // { dg-error "" } ansi forbids no type const k; // { dg-error "" } ansi forbids no type - mutable friend int j1 (); // { dg-error "" } non-member cannot be mutable + mutable friend int j1 (); // { dg-error "3:storage class specifiers" } non-member cannot be mutable mutable typedef int d; // { dg-error "" } non-object cannot be mutable - mutable int fn (); // { dg-error "" } non-object cannot be mutable - void fn (mutable int); // { dg-error "" } non-member cannot be mutable + mutable int fn (); // { dg-error "3:function .fn. cannot be declared .mutable." } non-object cannot be mutable + void fn (mutable int); // { dg-error "12:non-member .parameter. cannot be declared .mutable." } non-member cannot be mutable mutable static int s; // { dg-error "" } static cannot be mutable - mutable const int s1; // { dg-error "" } const cannot be mutable + mutable const int s1; // { dg-error "3:const .s1. cannot be declared .mutable." } const cannot be mutable mutable const int *s2; // ok - mutable int *const s3; // { dg-error "" } const cannot be mutable + mutable int *const s3; // { dg-error "3:const .s3. cannot be declared .mutable." } const cannot be mutable explicit A (); // ok }; -mutable int g; // { dg-error "" } non-member cannot be mutable +mutable int g; // { dg-error "1:non-member .g. cannot be declared .mutable." } non-member cannot be mutable explicit A::A () {} // { dg-error "" } only ctor decls can be explicit