From patchwork Tue Sep 24 19:07:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1166800 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-509523-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="FzY+frtm"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="f+bEw8S7"; 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 46d9g0413Dz9sNk for ; Wed, 25 Sep 2019 05:07:24 +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=nx1asBPgMtqSAujhatQjZjw1gFCLOPo9OMIKBWDy+ZeFt6NCs4 u0A384xMhtDXiFSaSdMp3EPvUCepuEGtYLwSzT/dSg/bywtD6JNhdsxRjGdZa/6t sb7QVegM4ZT2e0ty7P9SpeMOZix88NviJgE+ZyE5DQGCnHUTMLXPu+etE= 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=KZbVpmHj4F1z+Pfm6Slf0WDtpU0=; b=FzY+frtmptteHp5S2IVn lTjGiSolljAqDR3yC2TaCLolUZ//ogIVKKEVo0kyYtKLYEd2BK8RFQDqeVNTSaSJ VwbVd4GcI/BFJQpDxRais5bFyHUM3oRT7zXH7voL1cM/0zpCCLQfBpNGCZkgMPBF eaPFE/CkUgnC58RaCZTht0I= Received: (qmail 56542 invoked by alias); 24 Sep 2019 19:07:13 -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 56443 invoked by uid 89); 24 Sep 2019 19:07:12 -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=1610, HX-Spam-Relays-External:192.168.1.4, Bob, H*r:ip*192.168.1.4 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; Tue, 24 Sep 2019 19:07:11 +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 x8OJ4QQG168762; Tue, 24 Sep 2019 19:07:09 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-2019-08-05; bh=wf8lV2Y0JcGaWOI/XU91qMLU2IVVCkvr3a8F2TeNswE=; b=f+bEw8S7Ppx+dQWLNGjQHywsSRWo1NoPr7Ocz5uvL7d5ttZQSf7t6V+1Dq3cMNDsYu3h 6j/4V9/Fcm9yQVWSQCh2LF89m6mpHKd59X/dp0qUBJ9w/8YqXE9z8OQKqGOh/ayn3+Gx kiZcHl0B0LogI2cH+tX27EDGaZFO+Kzd7BFrH76eMjqH+/7uQ9n2JV8NqSLTx4u+y7p2 oim+lKgDNNsmK0FllAvQuWvtWhuj3F50p3wZEfbxby++CyKxtYHp7Qsp97Ks1KVFEUJN EQ4wXj7frtNPxXGTG2m9VSC4dnca6ExI0Y4tHPKkIs87ijPqcgTZ5rUY9rlDlyftYLk9 tw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2v5b9tr844-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Sep 2019 19:07:09 +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 x8OJ4pYD173099; Tue, 24 Sep 2019 19:07:08 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2v6yvpeyjc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Sep 2019 19:07:08 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8OJ7605007124; Tue, 24 Sep 2019 19:07:06 GMT Received: from [192.168.1.4] (/87.3.30.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 24 Sep 2019 12:07:05 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Use DECL_SOURCE_LOCATION more in name-lookup.c Message-ID: Date: Tue, 24 Sep 2019 21:07:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, Marek's recent fix prompted an audit of name-lookup.c and I found a few additional straightforward places where we should use a more accurate location. Tested x86_64-linux. Thanks, Paolo. /////////////////////// /cp 2019-09-24 Paolo Carlini * name-lookup.c (check_extern_c_conflict): Use DECL_SOURCE_LOCATION. (check_local_shadow): Use it in three additional places. /testsuite 2019-09-24 Paolo Carlini * g++.dg/diagnostic/redeclaration-1.C: New. * g++.dg/lookup/extern-c-hidden.C: Test location(s) too. * g++.dg/lookup/extern-c-redecl.C: Likewise. * g++.dg/lookup/extern-c-redecl6.C: Likewise. * g++.old-deja/g++.other/using9.C: Likewise. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 276104) +++ cp/name-lookup.c (working copy) @@ -2549,12 +2549,12 @@ check_extern_c_conflict (tree decl) if (mismatch) { auto_diagnostic_group d; - pedwarn (input_location, 0, + pedwarn (DECL_SOURCE_LOCATION (decl), 0, "conflicting C language linkage declaration %q#D", decl); inform (DECL_SOURCE_LOCATION (old), "previous declaration %q#D", old); if (mismatch < 0) - inform (input_location, + inform (DECL_SOURCE_LOCATION (decl), "due to different exception specifications"); } else @@ -2674,7 +2674,8 @@ check_local_shadow (tree decl) /* ARM $8.3 */ if (b->kind == sk_function_parms) { - error ("declaration of %q#D shadows a parameter", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "declaration of %q#D shadows a parameter", decl); return; } } @@ -2700,7 +2701,8 @@ check_local_shadow (tree decl) && (old_scope->kind == sk_cond || old_scope->kind == sk_for)) { auto_diagnostic_group d; - error ("redeclaration of %q#D", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "redeclaration of %q#D", decl); inform (DECL_SOURCE_LOCATION (old), "%q#D previously declared here", old); return; @@ -2723,7 +2725,8 @@ check_local_shadow (tree decl) && in_function_try_handler)) { auto_diagnostic_group d; - if (permerror (input_location, "redeclaration of %q#D", decl)) + if (permerror (DECL_SOURCE_LOCATION (decl), + "redeclaration of %q#D", decl)) inform (DECL_SOURCE_LOCATION (old), "%q#D previously declared here", old); return; Index: testsuite/g++.dg/diagnostic/redeclaration-1.C =================================================================== --- testsuite/g++.dg/diagnostic/redeclaration-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/redeclaration-1.C (working copy) @@ -0,0 +1,20 @@ +void +foo (int i) +{ + int i // { dg-error "7:declaration of .int i. shadows a parameter" } + (0); + + for (int j ;;) + int j // { dg-error "9:redeclaration of .int j." } + (0); +} + +void +bar (int i) + try + { } + catch (...) + { + int i // { dg-error "11:redeclaration of .int i." } + (0); + } Index: testsuite/g++.dg/lookup/extern-c-hidden.C =================================================================== --- testsuite/g++.dg/lookup/extern-c-hidden.C (revision 276104) +++ testsuite/g++.dg/lookup/extern-c-hidden.C (working copy) @@ -4,8 +4,8 @@ extern "C" float fabsf (float); // { dg-message " namespace Bob { - extern "C" float fabsf (float, float); // { dg-error "C language" } + extern "C" float fabsf (float, float); // { dg-error "20:conflicting C language" } extern "C" double fabs (double, double); // { dg-message "previous declaration" } } -extern "C" double fabs (double); // { dg-error "C language" } +extern "C" double fabs (double); // { dg-error "19:conflicting C language" } Index: testsuite/g++.dg/lookup/extern-c-redecl.C =================================================================== --- testsuite/g++.dg/lookup/extern-c-redecl.C (revision 276104) +++ testsuite/g++.dg/lookup/extern-c-redecl.C (working copy) @@ -8,4 +8,4 @@ namespace A { // next line should trigger an error because // it conflicts with previous declaration of foo_func (), due to // different exception specifications. -extern "C" void foo_func (); // { dg-error "C language linkage|exception specifications" } +extern "C" void foo_func (); // { dg-error "17:conflicting C language linkage|exception specifications" } Index: testsuite/g++.dg/lookup/extern-c-redecl6.C =================================================================== --- testsuite/g++.dg/lookup/extern-c-redecl6.C (revision 276104) +++ testsuite/g++.dg/lookup/extern-c-redecl6.C (working copy) @@ -16,10 +16,10 @@ extern "C" { namespace BAD { - long i; // { dg-error "C language linkage" } - double f; // { dg-error "C language linkage" } - int fn (); // { dg-error "C language linkage" } - int ai1[2]; // { dg-error "C language linkage" } + long i; // { dg-error "10:conflicting C language linkage" } + double f; // { dg-error "12:conflicting C language linkage" } + int fn (); // { dg-error "9:conflicting C language linkage" } + int ai1[2]; // { dg-error "9:conflicting C language linkage" } } } Index: testsuite/g++.old-deja/g++.other/using9.C =================================================================== --- testsuite/g++.old-deja/g++.other/using9.C (revision 276104) +++ testsuite/g++.old-deja/g++.other/using9.C (working copy) @@ -16,6 +16,6 @@ using ::a; extern "C" void foo (); // { dg-message "previous declaration" } namespace { - extern "C" int foo (); // { dg-error "C.*linkage" } + extern "C" int foo (); // { dg-error "18:conflicting C.*linkage" } using ::foo; // { dg-error "" } already in use }