From patchwork Sun Jan 13 23:33:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1024174 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-493970-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="Lj4QgJCI"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="FVWcTUIh"; 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 43dCbj5Bg4z9s3q for ; Mon, 14 Jan 2019 10:33:52 +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=Jwp8eO1PKiaoso117SHh6mIkAopH888U6wAb+xCMa89aG1AEc5 tP35xS+LDnFMPQlIdYi6aoGGgFt1mJbNpx+3MsVDDE3T1MkzIKbKUmAtE6z8TzqB rbE68SaS2OYLig22M2MNfqLR3JEBGsKXlCJFQod38LOr7zkfAoAljr6SU= 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=ZtqEiNqY1FwWq78CQpiQHCT/7G0=; b=Lj4QgJCIM6nlGlNlYKmi xc+PcCt/0KU5EdUToqSmmzkBlr/sBdUuRi/lGxvOG0Wo9x2avbMWAHmg5KfKWpf5 cDZK4ocrR1t8qi58vH9Hltr0WPH5ySu+VZBdq5lzrYAy77rX0ZrRQdPxR2C/H0lr jm2/34uDk8wrY7R5k3KUw2E= Received: (qmail 128704 invoked by alias); 13 Jan 2019 23:33:45 -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 128682 invoked by uid 89); 13 Jan 2019 23:33:45 -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, SPF_PASS autolearn=ham version=3.3.2 spammy=error_mark_node 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, 13 Jan 2019 23:33:43 +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 x0DNTZEj065959; Sun, 13 Jan 2019 23:33:41 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=MdpByBW2wBn1S6N0dRyL06Nwxf4uXTnuLZlfxPa7N/0=; b=FVWcTUIh+JBWXjy6NrgKUHO5PLOW85wsZw/bNW9ryG4JGPGPCnMYYVPlX9Oj5hhzSfBR gFPmmC6G4McgLruu2b0JkoIY35KW5RY+OjmvGs3Nyu8EjtO9GwmDbEtFp/Iaj/d3vnBV MRgjn5Mz3rxxhQhHoEbB0RAw52UBxYXHfFhI5ESPCGE+zR1dexkuVMVNLBi2o6Za4shP BCpn6KM1QdDTenHLFlrbmtbtYEeMPLCFuRyshRY74+1fTc6AlSgKyi8IczXQOK+rjmC/ VZf4zOqsk8q+Wr32/RLIwz/fBbYk06QcIUl0GqFrh57Itko9vPnW8x5JoiXienWoQCK8 DQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2pybjrtvuf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 13 Jan 2019 23:33:41 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0DNXZPe029015 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 13 Jan 2019 23:33:36 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0DNXY6F020714; Sun, 13 Jan 2019 23:33:35 GMT Received: from [192.168.1.4] (/79.19.31.237) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 13 Jan 2019 15:33:34 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Fix locations of two "typedef is initialized" errors Message-ID: <6e6ead42-9946-a758-c24e-3cb1f83bb688@oracle.com> Date: Mon, 14 Jan 2019 00:33:24 +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, I think we need this patch too in order to have consistent locations for the set of error messages about invalid initializers - most of which I changed in patch 23 of this series - and also in order to have consistent locations for the two cases - in class, out of class - of ill-formed initialized typedefs. Note that when we'll consistently have precise locations stored in the initializers we'll have to revisit the already mentioned check in check_methods and the one changed here, in start_decl, which currently both don't have readily available the initializer itself. Also note that this patch relies on the patch I sent earlier today, that is relies on a more accurate location stored in the TYPE_DECL. Tested x86_64-linux. Thanks, Paolo. ///////////////////////// /cp 2019-01-13 Paolo Carlini * decl.c (start_decl): Improve error location. * decl2.c (grokfield): Likewise. /testsuite 2019-01-13 Paolo Carlini * g++.dg/diagnostic/typedef-initialized.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 267887) +++ cp/decl.c (working copy) @@ -5059,7 +5059,8 @@ start_decl (const cp_declarator *declarator, if (initialized && TREE_CODE (decl) == TYPE_DECL) { - error ("typedef %qD is initialized (use decltype instead)", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "typedef %qD is initialized (use decltype instead)", decl); return error_mark_node; } Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 267887) +++ cp/decl2.c (working copy) @@ -820,7 +820,8 @@ grokfield (const cp_declarator *declarator, if (TREE_CODE (value) == TYPE_DECL && init) { - error ("typedef %qD is initialized (use decltype instead)", value); + error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value)), + "typedef %qD is initialized (use decltype instead)", value); init = NULL_TREE; } Index: testsuite/g++.dg/diagnostic/typedef-initialized.C =================================================================== --- testsuite/g++.dg/diagnostic/typedef-initialized.C (nonexistent) +++ testsuite/g++.dg/diagnostic/typedef-initialized.C (working copy) @@ -0,0 +1,6 @@ +struct S +{ + typedef int i __attribute__((unused)) = 1; // { dg-error "15:typedef .i. is initialized" } +}; + +typedef int i __attribute__((unused)) = 1; // { dg-error "13:typedef .i. is initialized" }