From patchwork Sun Jan 6 09:47:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1021062 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-493464-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="mRzl5L24"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="bRgeDJah"; 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 43XYbT5qR4z9sBZ for ; Sun, 6 Jan 2019 20:47:29 +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=i5ilprqYcxqoT+6St68E5j6OedsdNGoQJ5yPT0ZTepovWkRwQQ tFH6hUl4y/sWwk6hQKe/PM0Wx2q5AwgYQwMg9UvwgFCyXUl27u4jhnNDEHC+cq0T hE4AFLHdmcIDKLuEy9UieSdcSMZwcFmlLYlhV5ykcsHvxdkjan2zuyjms= 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=xOjHpA3RhAFv/QNCC+fArHnXtdY=; b=mRzl5L248DQg4VhtkQuJ z6EjXXqzoCjLTAXHZs4itRxs+djC6P2pV1WK4fhlRk1LPiMypu4cPjoGJ+9t09Jb RG8Jo7ViI8W/VNpMICB8W/cs54J2LpLraQRD0NqFK79zDpEZWD2Bf9FuS9N4VHYq QAvBvJXqSAkfGM/C+cur0s4= Received: (qmail 128611 invoked by alias); 6 Jan 2019 09:47:20 -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 128602 invoked by uid 89); 6 Jan 2019 09:47:19 -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=H*r:8.13.8, olddeja, old-deja, UD:oracle.com X-HELO: aserp2130.oracle.com Received: from aserp2130.oracle.com (HELO aserp2130.oracle.com) (141.146.126.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 06 Jan 2019 09:47:18 +0000 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x069ceqN129567; Sun, 6 Jan 2019 09:47:16 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=W1GS9zZAc5q7d/y6+m97fu+ldsostWBE9uf7C+nBr6g=; b=bRgeDJahLwrziUIHkPn3HCgZ86Ga/vyQhnd0PQYenUDsAmZWE27ajNIjTnCCcI7sqoe1 W/xurQAobR7G7WNA6w5RmZ7W8dlq+EU0sXUXoMKMBkSO5QitMq/7Nre7g0jyW4N9bpK3 9xXtZTx/OlxKsuPXosectCtcITdxqOgq1iQswM1NvahOnLTysG1+GYqPbDBcVMoh8VSO FJImzlPYMzZFT735z8G5zKXSanJWOIkDIQa3NP3zrjoiYQmxiC4zt7eQ/qlqo2I83+ue hBm1bXj6xyedHcgav9Ygphf9cQJ/GHoitF0a4Smiyfdsu9N/MKZwEcKdgt8IgpDS+5bv tQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2ptj3djeqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 06 Jan 2019 09:47:16 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x069lF4h002642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 6 Jan 2019 09:47:15 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x069lEe0030123; Sun, 6 Jan 2019 09:47:14 GMT Received: from [192.168.1.4] (/80.181.224.14) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 06 Jan 2019 09:47:13 +0000 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill , David Malcolm From: Paolo Carlini Subject: [C++ Patch] Fix a start_decl location Message-ID: Date: Sun, 6 Jan 2019 10:47:11 +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, this was supposed to be very straightforward but required a little more. A first draft of the patch exploited DECL_SOURCE_LOCATION but that failed when I tested the case of a function already defined in class: at that point the location of the decl is that of the in class definition itself not that of the wrong redeclaration. Thus the use of declarator->id_loc. Tested x86_64-linux. A final note, about a detail already noticed many other times: the location we store in such cases is that of K not that of f, and that seems suboptimal to me: in principle we should point to f and possibly have the wavy queue of the caret going back to K, at least that's what clang does... no idea id David has this kind of tweak in his todo list. Thanks, Paolo. //////////////////////// /cp 2019-01-06 Paolo Carlini * decl.c (start_decl): Improve permerror location. /testsuite 2019-01-06 Paolo Carlini * g++.dg/diagnostic/out-of-class-redeclaration.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 267600) +++ cp/decl.c (working copy) @@ -5202,7 +5202,8 @@ start_decl (const cp_declarator *declarator, if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl) /* Aliases are definitions. */ && !alias) - permerror (input_location, "declaration of %q#D outside of class is not definition", + permerror (declarator->id_loc, + "declaration of %q#D outside of class is not definition", decl); } Index: testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C =================================================================== --- testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C (nonexistent) +++ testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C (working copy) @@ -0,0 +1,13 @@ +// Adapted from g++.old-deja/g++.law/arm8.C + +struct K { + void f(int); +}; + +void K::f(int); // { dg-error "6:declaration of .void K::f\\(int\\). outside of class" } + +struct L { + void g(int) {} +}; + +void L::g(int); // { dg-error "6:declaration of .void L::g\\(int\\). outside of class" }