From patchwork Wed Jun 5 15:06:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1110541 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-502398-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="fn1l2MQK"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="XuWoBvYJ"; 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 45JsZT0F61z9s3l for ; Thu, 6 Jun 2019 01:06:38 +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=BtjwQvMoh9s3uHyjkGc0txmYlEicxFNwVSlnGicaIRzjJZjxLf g1iOv/E3uhEP5JTnzQeroQGH53N4otHkbMUP5W2bocSOeq5YFRF17IBSZY0ka7ZZ NSW2L5mIwHbZnXW2TNYqH6afmWPI31wsH6gQyJPAzprFZFh4HnCoTfMRE= 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=tDFurA4OBqVrA7SeoeLvLGJCMyc=; b=fn1l2MQKpXvGRATISGxL 3b4Rsg1VcE3dyVxLX/fFeGJYyc9ofqBfbp+AQzkdk1FGsFr4fUPZSYFaN6KVcnsr oTy4lz35PjaWz/12MauuCWNOiY56agSrZDOsfhv5LTEzZCyyzcJiG+0jlJHUHJ6Q i7Eky0QfMDqT74ojcHg7e0I= Received: (qmail 7228 invoked by alias); 5 Jun 2019 15:06:31 -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 7218 invoked by uid 89); 5 Jun 2019 15:06:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.4 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=input_location, funcdef_flag, error_at, *declarator 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; Wed, 05 Jun 2019 15:06:29 +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 x55F43FQ021330; Wed, 5 Jun 2019 15:06:27 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=xqBLFZD0GKSZ29atsO0Zpu1Bni4i+sugzY5LJryRtkQ=; b=XuWoBvYJS8dHy57c8OTZF4cZQs6aw9s9EHgAFKRkUizJry4UQPDySRuHejJFhD4sjSGC 5iMnhzgYh+ZLDvQvkJYlVkeyflXqI+i/eahOajrPTku4yra3YKEK9D1JCTiUkmSBpd8r tjm+7da7BM144MMmsB2K7hWIFLNn/cuGOlbQrxuVWhJuETHEynhxtJ3Vm2Wvh2HI4Dew 7RzM+GFBwFiEwdPDBzJtoT0HiWJGVYYM++wg1ZTSUAJY7E1GZIOXb3wa3md/xKrndd68 Kc1eoTVyS4zK3j1WwZFhHLAxepS+Ga+JNutZZ0CUNzW8N3P0buMD0EBQu3vrsto25IKs 3Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2suj0qk5bb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Jun 2019 15:06:27 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x55F5369061600; Wed, 5 Jun 2019 15:06:26 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2swngkyd4y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Jun 2019 15:06:26 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x55F6PTW025566; Wed, 5 Jun 2019 15:06:25 GMT Received: from [192.168.1.4] (/79.42.221.26) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 05 Jun 2019 08:06:24 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve check_special_function_return_type locations Message-ID: <19fe3e47-a1a6-6ac5-aad6-e780b48381a2@oracle.com> Date: Wed, 5 Jun 2019 17:06:20 +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 certainly we can do better than using input_location. In principle we could also pass the location of the entity (constructor, destructor, etc) itself or something else but I think it makes a lot of sense to simply include locations[ds_type_spec] in the computation, seems consistent with the existing case of spurious qualifiers (ICC does something similar AFAICS). Tested x86_64-linux. Thanks, Paolo. ////////////////////// /cp 2019-06-05 Paolo Carlini * decl.c (smallest_type_location): Add. (check_special_function_return_type): Use it. (grokdeclarator): Lkewise. /testsuite 2019-06-05 Paolo Carlini * g++.dg/diagnostic/return-type-invalid-1.C: New. * g++.old-deja/g++.brendan/crash16.C: Adjust. * g++.old-deja/g++.law/ctors5.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 271949) +++ cp/decl.c (working copy) @@ -10111,6 +10111,15 @@ smallest_type_quals_location (int type_quals, cons return loc; } +/* Returns the smallest among the latter and locations[ds_type_spec]. */ + +static location_t +smallest_type_location (int type_quals, const location_t* locations) +{ + location_t loc = smallest_type_quals_location (type_quals, locations); + return min_location (loc, locations[ds_type_spec]); +} + /* Check that it's OK to declare a function with the indicated TYPE and TYPE_QUALS. SFK indicates the kind of special function (if any) that this function is. OPTYPE is the type given in a conversion @@ -10129,7 +10138,8 @@ check_special_function_return_type (special_functi { case sfk_constructor: if (type) - error ("return type specification for constructor invalid"); + error_at (smallest_type_location (type_quals, locations), + "return type specification for constructor invalid"); else if (type_quals != TYPE_UNQUALIFIED) error_at (smallest_type_quals_location (type_quals, locations), "qualifiers are not allowed on constructor declaration"); @@ -10142,7 +10152,8 @@ check_special_function_return_type (special_functi case sfk_destructor: if (type) - error ("return type specification for destructor invalid"); + error_at (smallest_type_location (type_quals, locations), + "return type specification for destructor invalid"); else if (type_quals != TYPE_UNQUALIFIED) error_at (smallest_type_quals_location (type_quals, locations), "qualifiers are not allowed on destructor declaration"); @@ -10157,7 +10168,8 @@ check_special_function_return_type (special_functi case sfk_conversion: if (type) - error ("return type specified for %", optype); + error_at (smallest_type_location (type_quals, locations), + "return type specified for %", optype); else if (type_quals != TYPE_UNQUALIFIED) error_at (smallest_type_quals_location (type_quals, locations), "qualifiers are not allowed on declaration of " @@ -10168,7 +10180,8 @@ check_special_function_return_type (special_functi case sfk_deduction_guide: if (type) - error ("return type specified for deduction guide"); + error_at (smallest_type_location (type_quals, locations), + "return type specified for deduction guide"); else if (type_quals != TYPE_UNQUALIFIED) error_at (smallest_type_quals_location (type_quals, locations), "qualifiers are not allowed on declaration of " @@ -10438,10 +10451,8 @@ grokdeclarator (const cp_declarator *declarator, if (initialized > 1) funcdef_flag = true; - location_t typespec_loc = smallest_type_quals_location (type_quals, - declspecs->locations); - typespec_loc = min_location (typespec_loc, - declspecs->locations[ds_type_spec]); + location_t typespec_loc = smallest_type_location (type_quals, + declspecs->locations); if (typespec_loc == UNKNOWN_LOCATION) typespec_loc = input_location; Index: testsuite/g++.dg/diagnostic/return-type-invalid-1.C =================================================================== --- testsuite/g++.dg/diagnostic/return-type-invalid-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/return-type-invalid-1.C (working copy) @@ -0,0 +1,27 @@ +struct S1 +{ + int S1(); // { dg-error "3:return type" } + int ~S1(); // { dg-error "3:return type" } + int operator int(); // { dg-error "3:return type" } +}; + +struct S2 +{ + const int S2(); // { dg-error "3:return type" } + const int ~S2(); // { dg-error "3:return type" } + const int operator int(); // { dg-error "3:return type" } +}; + +struct S3 +{ + volatile int S3(); // { dg-error "3:return type" } + volatile int ~S3(); // { dg-error "3:return type" } + volatile int operator int(); // { dg-error "3:return type" } +}; + +struct S4 +{ + const volatile int S4(); // { dg-error "3:return type" } + const volatile int ~S4(); // { dg-error "3:return type" } + const volatile int operator int(); // { dg-error "3:return type" } +}; Index: testsuite/g++.old-deja/g++.brendan/crash16.C =================================================================== --- testsuite/g++.old-deja/g++.brendan/crash16.C (revision 271949) +++ testsuite/g++.old-deja/g++.brendan/crash16.C (working copy) @@ -3,12 +3,13 @@ // GROUPS passed old-abort class Graph { // { dg-error "1:new types|1: note: \\(perhaps" } +// { dg-error "1:return type" "" { target *-*-* } .-1 } public: unsigned char N; Graph(void) {} // { dg-message "7:'Graph" } } -Graph::Graph(void) // { dg-error "18:return type|1: error: redefinition" } +Graph::Graph(void) // { dg-error "1:redefinition" } { N = 10; } Index: testsuite/g++.old-deja/g++.law/ctors5.C =================================================================== --- testsuite/g++.old-deja/g++.law/ctors5.C (revision 271949) +++ testsuite/g++.old-deja/g++.law/ctors5.C (working copy) @@ -16,6 +16,7 @@ class X // { dg-message "7:X::X|candidate ex class Y // { dg-error "1:new types may not be defined in a return type" "err" } // { dg-message "1:\\(perhaps a semicolon is missing after the definition of 'Y'\\)" "note" { target *-*-* } .-1 } + // { dg-error "1:return type specification for constructor invalid" "err" { target *-*-* } .-2 } { private: X xx; @@ -22,7 +23,7 @@ class Y // { dg-error "1:new types may not be defi public: Y(); } -X::X( int xi ) // { dg-error "14:return type specification for constructor invalid" "err" } +X::X( int xi ) // { dg-message "1:X::X|candidate expects" "match candidate text" { target *-*-* } .-1 } { x = xi;