From patchwork Thu Nov 2 18:24:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 833475 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-465776-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="KZOIazyz"; 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 3ySYQq57FVz9sNd for ; Fri, 3 Nov 2017 05:24:50 +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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=tmer5RKUjYcYt2HvqOdeJjBzKjkcFxO5/fzJ0bb3GDDaMJxbp3 UMoC4wXPUgRR2jLHlcwdXmTJIS7F+py46JOXgrVAQl5jWp0b1DCHH1rKLoG81UL+ L8900ofGl2W4BdD7XE6vS56MnUjd4CpMASy+w25U34d5S4U/4sQL8/t4c= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=Cp6dHeKeBXg0CXAX+Exp3cpgfKk=; b=KZOIazyzUMSJd5VUTG0v Q+wZkpdeuCvNFgvfItw9DditN+AKRhCBL0pK0+cO+2d2AqQAHTKlUso/TXLOAlGR urtGvXFYjzvSpsgFn19A6DFIedBvzsbD4BGSTT5H6exJ+uU0vtd7I5Xiiw/MgmrQ nZvLr5qqZp4OFnBOsjW/RiM= Received: (qmail 75927 invoked by alias); 2 Nov 2017 18:24:39 -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 41995 invoked by uid 89); 2 Nov 2017 18:24:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=friend X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Nov 2017 18:24:25 +0000 Received: by mail-yw0-f171.google.com with SMTP id k11so401216ywh.1 for ; Thu, 02 Nov 2017 11:24:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=AWIdmuESIIZCkPoLIYFRZS37HOXhG7GDKDdeeap54yE=; b=TN6BZrE6r8Iuyc94Yy6PtGhPJdC4DgyTxcE4ZqH5ibeh2VXcwDhc5AC7BI9ckupJ33 /ECgRjFD1WMQIu3WyNaFbpJWPTtpa/CYcUu7Q/nLESVlUVn9ai6K4S/VybYnMRQhie8C iCragQaiB+Vl3Htn2PLT3NXw5rOLAKxku122Zvc6l4ekdzD3/MMDbHCN2jolmUKONQCL O0gKaIznJDqOboLiC1UAX0wZkAPnZrTOPUeE0nc4o4fI71W+qo2jCulGy713/tA/DHQm Be4cxdF7dZKBbMiSGxPxuBdwvfOKOP94zkjnAsbxg8D0vbHJNwLiNjQImvIDi+4Y8z+f sEWQ== X-Gm-Message-State: AJaThX7V8SbD6AbuFGjR7S3QVdfEp9yHOMdBCMY0e+f0kL8nPTe7k4QJ 8R4vPbNysWO+d+StQHaBXww= X-Google-Smtp-Source: ABhQp+SC6g6B81iet9jmPEHDZxttdiumYGltVTkuSm0jxSxG1VYPVuLuzxrTKXguttBxRAgTwvYWpg== X-Received: by 10.37.38.206 with SMTP id m197mr347495ybm.45.1509647063281; Thu, 02 Nov 2017 11:24:23 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::4fa5]) by smtp.googlemail.com with ESMTPSA id y11sm1672766ywc.70.2017.11.02.11.24.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 11:24:22 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [PR c++/82710] false positive paren warning Message-ID: <39398177-ddf0-51de-78d1-7129062ab448@acm.org> Date: Thu, 2 Nov 2017 14:24:21 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 This patch fixes pr82710, were we erroneously warn on something like: friend class_X (::other::name (...)); the parens are needed, otherwise the '::other' is taken to be a qualified lookup inside the class_X. Unfortunately, at the point we can check, we've lost information that '::' was used. So I back off when we see a qualified name there. nathan 2017-11-02 Nathan Sidwell PR c++/82710 * decl.c (grokdeclarator): Don't warn when parens protect a return type from a qualified name. PR c++/82710 * g++.dg/warn/pr82710.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 254344) +++ cp/decl.c (working copy) @@ -10788,18 +10788,25 @@ grokdeclarator (const cp_declarator *dec attr_flags); } + inner_declarator = declarator->declarator; + /* We don't want to warn in parmeter context because we don't yet know if the parse will succeed, and this might turn out to be a constructor call. */ if (decl_context != PARM - && declarator->parenthesized != UNKNOWN_LOCATION) + && declarator->parenthesized != UNKNOWN_LOCATION + /* If the type is a class and the inner name used a global + namespace qualifier, we need the parens. Unfortunately + all we can tell is that a qualified name was used. */ + && !(CLASS_TYPE_P (type) + && inner_declarator + && inner_declarator->kind == cdk_id + && inner_declarator->u.id.qualifying_scope)) warning_at (declarator->parenthesized, OPT_Wparentheses, "unnecessary parentheses in declaration of %qs", name); if (declarator->kind == cdk_id || declarator->kind == cdk_decomp) break; - inner_declarator = declarator->declarator; - switch (declarator->kind) { case cdk_array: Index: testsuite/g++.dg/warn/pr82710.C =================================================================== --- testsuite/g++.dg/warn/pr82710.C (revision 0) +++ testsuite/g++.dg/warn/pr82710.C (working copy) @@ -0,0 +1,32 @@ +// { dg-additional-options -Wparentheses } + +// the MVP warning triggered on a friend decl. */ +class X; + +namespace here +{ + // these friends + X friendFunc1(); + X *friendFunc2 (); + int friendFunc3 (); +} + +namespace nm +{ + namespace here + { + // Not these friends + void friendFunc1 (); + void friendFunc2 (); + void friendFunc3 (); + } + + class TestClass + { + friend X (::here::friendFunc1 ()); // parens are needed + friend X *(::here::friendFunc2 ()); // { dg-warning "" } + friend X *::here::friendFunc2 (); + friend int (::here::friendFunc3 ()); // { dg-warning "" } + }; +} +