From patchwork Fri Aug 11 16:56:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 800660 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-460240-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vDL93jwW"; 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 3xTWPv5vP3z9s7F for ; Sat, 12 Aug 2017 02:57:06 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=At88nnwnERKY6ubqLiVGD9MY1ZrvfFno/zEMevKT7DJadZbZ8cmfK yNncr4K6HpqxXEgRWQOwLRl8nvm9x++acMNxUEsUAaYAAFnaZzl+dhPrIKNbWZ3V hxZeQQcD8qgF5g6cfduefDQNwMZ1QnjllWyUbdERYjC1hbpO2tud3c= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=cx+htsYNBmA2mdmeXR3C6JutXEw=; b=vDL93jwW8F1/pQBUgzdd zQGukYAIwe2n8+3t41TqPONN0roeg4QSQh2cULM5csD8p5GYtaCy3DHW/aNhW6uz 8ASPJVOsqVWT7LH47a2LazH6RkBWVJwvb7/g184Km9QzmNzdTFOV9d6jgctxrH2r HMQ2DKzxTj6kRUbYC+Cc3M4= Received: (qmail 11326 invoked by alias); 11 Aug 2017 16:56:57 -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 11292 invoked by uid 89); 11 Aug 2017 16:56:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=theyd, they'd, Hx-languages-length:2297 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Aug 2017 16:56:54 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B444E61475; Fri, 11 Aug 2017 16:56:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B444E61475 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek@redhat.com Received: from redhat.com (ovpn-204-44.brq.redhat.com [10.40.204.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD736A21BE; Fri, 11 Aug 2017 16:56:51 +0000 (UTC) Date: Fri, 11 Aug 2017 18:56:48 +0200 From: Marek Polacek To: GCC Patches , Joseph Myers Subject: C PATCH to fix bogus inform with -Wc++-compat (PR c/81795) Message-ID: <20170811165648.GT17069@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) Pretty trivial patch -- these two informs weren't properly guarded so they'd trigger even if the warning was disabled via #pragma. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-08-11 Marek Polacek PR c/81795 * c-decl.c (pushtag): Only print inform if the warning was printed. (grokdeclarator): Likewise. * gcc.dg/pr81795.c: New test. Marek diff --git gcc/c/c-decl.c gcc/c/c-decl.c index d21fbc5883e..323d4480609 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -1557,11 +1557,10 @@ pushtag (location_t loc, tree name, tree type) && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) != TYPE_MAIN_VARIANT (type))) { - warning_at (loc, OPT_Wc___compat, - ("using %qD as both a typedef and a tag is " - "invalid in C++"), - b->decl); - if (b->locus != UNKNOWN_LOCATION) + if (warning_at (loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), b->decl) + && b->locus != UNKNOWN_LOCATION) inform (b->locus, "originally defined here"); } } @@ -6596,11 +6595,10 @@ grokdeclarator (const struct c_declarator *declarator, || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type)) { - warning_at (declarator->id_loc, OPT_Wc___compat, - ("using %qD as both a typedef and a tag is " - "invalid in C++"), - decl); - if (b->locus != UNKNOWN_LOCATION) + if (warning_at (declarator->id_loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), decl) + && b->locus != UNKNOWN_LOCATION) inform (b->locus, "originally defined here"); } } diff --git gcc/testsuite/gcc.dg/pr81795.c gcc/testsuite/gcc.dg/pr81795.c index e69de29bb2d..b035bd0b530 100644 --- gcc/testsuite/gcc.dg/pr81795.c +++ gcc/testsuite/gcc.dg/pr81795.c @@ -0,0 +1,14 @@ +/* PR c/81795 */ +/* { dg-do compile } */ +/* { dg-options "-Wc++-compat" } */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wc++-compat" + +struct S { int f; }; /* { dg-bogus "note: originally defined here" } */ +typedef int S; /* { dg-bogus "invalid in C\[+\]\[+\]" } */ + +typedef int T; /* { dg-bogus "note: originally defined here" } */ +struct T { int f; }; /* { dg-bogus "invalid in C\[+\]\[+\]" } */ + +#pragma GCC diagnostic pop