From patchwork Mon Jun 15 19:40:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1309692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=YQwbLZe8; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49m1sS3HvXz9s1x for ; Tue, 16 Jun 2020 05:41:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22C113858D35; Mon, 15 Jun 2020 19:40:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22C113858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592250057; bh=rXO1XtASimaqL2bQNZgYdh7YGCwSciwQ+Eiz8QaPFug=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YQwbLZe8fTVwPvXGEDNZ4RoSPsgAhBqzUAGdQffYFJan+GDOMoaTNE3tD90GuxXO1 EHZbhOPJGsXqPO332SFMGv3XiEBBGPZtkdOHYKxZSsNjECPp7eQsdj3EVq225+Q1sL b/r0h4keY8uZxBwXODo4esUJoFHKTuIUdUmeRh50= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 1D6C43858D35 for ; Mon, 15 Jun 2020 19:40:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D6C43858D35 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-ZWXBcQoTP3CKwG5fbRLJ2g-1; Mon, 15 Jun 2020 15:40:47 -0400 X-MC-Unique: ZWXBcQoTP3CKwG5fbRLJ2g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 216D910AEA05; Mon, 15 Jun 2020 19:40:46 +0000 (UTC) Received: from localhost (unknown [10.33.36.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDBA17CAB1; Mon, 15 Jun 2020 19:40:45 +0000 (UTC) Date: Mon, 15 Jun 2020 20:40:44 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix bogus "does not declare anything" warning (PR 66159) Message-ID: <20200615194044.GB4137376@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-16.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Cc: Nathan Sidwell Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Ping ... G++ gives a bogus warning for 'struct A; using B = struct ::A;' complaining that the elaborated-type-specifier doesn't declare anything. That's true, but it's not trying to declare struct ::A, just refer to it unambiguously. Do not emit the warning unless we're actually parsing a declaration. This also makes the relevant warning depend on -Wredundant-decls (which is not part of -Wall or -Wextra) so it can be disabled on the command line or by using #pragma. This means the warning will no longer be given by default, so some tests need -Wredundant-decls added. gcc/cp/ChangeLog: PR c++/66159 * parser.c (cp_parser_elaborated_type_specifier): Do not warn unless in a declaration. Make warning depend on WOPT_redundant_decls. gcc/testsuite/ChangeLog: PR c++/66159 * g++.dg/parse/specialization1.C: Remove dg-warning. * g++.dg/warn/forward-inner.C: Add -Wredundant-decls. Check alias-declaration using elaborated-type-specifier. * g++.dg/warn/pr36999.C: Add -Wredundant-decls. Is it OK to make this warning no longer emitted by default, and not even with -Wall -Wextra? Would it be better to add a new option for this specific warning, which would be enabled by -Wall and also by -Wredundant-decls? Maybe -Wredundant-decls-elaborated-type or something. commit c254d7cb3977484fd4737b973a87c1df98c30e01 Author: Jonathan Wakely Date: Wed May 27 10:40:38 2020 +0100 c++: Fix bogus "does not declare anything" warning (PR 66159) G++ gives a bogus warning for 'struct A; using B = struct ::A;' complaining that the elaborated-type-specifier doesn't declare anything. That's true, but it's not trying to declare struct ::A, just refer to it unambiguously. Do not emit the warning unless we're actually parsing a declaration. This also makes the relevant warning depend on -Wredundant-decls (which is not part of -Wall or -Wextra) so it can be disabled on the command line or by using #pragma. This means the warning will no longer be given by default, so some tests need -Wredundant-decls added. gcc/cp/ChangeLog: PR c++/66159 * parser.c (cp_parser_elaborated_type_specifier): Do not warn unless in a declaration. Make warning depend on WOPT_redundant_decls. gcc/testsuite/ChangeLog: PR c++/66159 * g++.dg/parse/specialization1.C: Remove dg-warning. * g++.dg/warn/forward-inner.C: Add -Wredundant-decls. Check alias-declaration using elaborated-type-specifier. * g++.dg/warn/pr36999.C: Add -Wredundant-decls. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 54ca875ce54..5287ab34752 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18917,8 +18917,10 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, here. */ if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON) - && !is_friend && !processing_explicit_instantiation) - warning (0, "declaration %qD does not declare anything", decl); + && !is_friend && is_declaration + && !processing_explicit_instantiation) + warning (OPT_Wredundant_decls, + "declaration %qD does not declare anything", decl); type = TREE_TYPE (decl); } diff --git a/gcc/testsuite/g++.dg/parse/specialization1.C b/gcc/testsuite/g++.dg/parse/specialization1.C index 44a98baa2f4..6d83bc4f254 100644 --- a/gcc/testsuite/g++.dg/parse/specialization1.C +++ b/gcc/testsuite/g++.dg/parse/specialization1.C @@ -4,4 +4,3 @@ template class A; template class A::B; // { dg-error "declaration" "err" } -// { dg-warning "declaration" "warn" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/warn/forward-inner.C b/gcc/testsuite/g++.dg/warn/forward-inner.C index 5336d4ed946..1c10ec44a54 100644 --- a/gcc/testsuite/g++.dg/warn/forward-inner.C +++ b/gcc/testsuite/g++.dg/warn/forward-inner.C @@ -1,5 +1,6 @@ // Check that the compiler warns about inner-style forward declarations in // contexts where they're not actually illegal, but merely useless. +// { dg-options "-Wredundant-decls" } // Verify warnings for and within classes, and by extension, struct and union. class C1; @@ -70,7 +71,7 @@ template class TC6::TC7; // Valid explicit instantiation, no warning // Verify that friend declarations, also easy to confuse with forward -// declrations, are similarly not warned about. +// declarations, are similarly not warned about. class C8 { public: class C9 { }; @@ -79,3 +80,10 @@ class C10 { public: friend class C8::C9; // Valid friend declaration, no warning }; + +#if __cplusplus >= 201103L +// Verify that alias-declarations using an elaborated-type-specifier and +// nested-name-specifier are not warned about (PR c++/66159). +struct C11; +using A1 = struct ::C11; // Valid alias-decl, no warning +#endif diff --git a/gcc/testsuite/g++.dg/warn/pr36999.C b/gcc/testsuite/g++.dg/warn/pr36999.C index ce2286efcf4..6f69e192d02 100644 --- a/gcc/testsuite/g++.dg/warn/pr36999.C +++ b/gcc/testsuite/g++.dg/warn/pr36999.C @@ -1,5 +1,6 @@ /* PR36999: Erroneous "does not declare anything" warnings. */ /* { dg-do compile } */ +/* { dg-options "-Wredundant-decls" } */ class C1 { public: class C2 { };