Bug 82710 - [8 Regression] Incorrect warning:unnecessary parentheses in declaration of global friend functions [-Werror=parentheses]
Summary: [8 Regression] Incorrect warning:unnecessary parentheses in declaration of gl...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2017-10-25 07:42 UTC by Andi
Modified: 2017-11-03 13:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-10-25 00:00:00


Attachments
test case to reproduce the warning (727 bytes, application/zip)
2017-10-25 07:42 UTC, Andi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andi 2017-10-25 07:42:29 UTC
Created attachment 42466 [details]
test case to reproduce the warning

When trying to build the mozilla-central repo with treat warnings as errors I get this error:

In file included from /root/firefox-gcc-last/image/SVGDocumentWrapper.cpp:27:0,
                  from /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/image/Unified_cpp_image1.cpp:38:
 /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/dist/include/mozilla/dom/SVGSVGElement.h:85:19: error: unnecessary parentheses in declaration of 'NS_NewSVGSVGElement' [-Werror=parentheses]
    friend nsresult (::NS_NewSVGSVGElement(nsIContent **aResult,

The code can be found here: https://dxr.mozilla.org/mozilla-central/source/dom/svg/SVGSVGElement.h#85

I consider this to be a bug since the resolution operator is used in order to point the global function NS_NewSVGSVGElement that is not in the mozilla::dom namespace.

In order to be more easely debuged I've created test case, that is attached to this bug. For my test case I got the same warning:
>>In file included from main.cpp:1:0:
>>def.h:13:20: error: unnecessary parentheses in declaration of 'friendFunc' [->>Werror=parentheses]
>>   friend TestClass (::friendFunc());


The way how I build it is:
# g++-8 -Wall -Werror main.cpp
Comment 1 Sylvestre Ledru 2017-10-25 07:47:02 UTC
With gcc-8 (Debian 8-20171023-1) 8.0.0 20171023 (experimental) [trunk revision 253997]
Comment 2 Richard Biener 2017-10-25 08:30:00 UTC
I think this warning was intentionally added.  Splitting to some other warning option might be possible though.
Comment 3 Nathan Sidwell 2017-10-25 11:15:00 UTC
Richard is correct, and I picked the existing Wparenthesis warning to enable it.  However, I think this is a false positive as Andi states.
Comment 4 Jonathan Wakely 2017-10-25 12:31:29 UTC
Self-contained testcase (rather than a zip file with several files in, which https://gcc.gnu.org/bugs/ says we don't want):

class X;

X friendFunc();

namespace nm
{
  class TestClass
  {
    friend X (::friendFunc());
  };
}
Comment 5 Nathan Sidwell 2017-11-02 18:27:00 UTC
Author: nathan
Date: Thu Nov  2 18:26:29 2017
New Revision: 254349

URL: https://gcc.gnu.org/viewcvs?rev=254349&root=gcc&view=rev
Log:
[PR c++/82710] false positive paren warning

https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00119.html
	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.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pr82710.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Nathan Sidwell 2017-11-02 18:47:30 UTC
Fixed r254349.
Comment 7 Nathan Sidwell 2017-11-03 13:16:37 UTC
Author: nathan
Date: Fri Nov  3 13:16:06 2017
New Revision: 254371

URL: https://gcc.gnu.org/viewcvs?rev=254371&root=gcc&view=rev
Log:
[PR c++/82710] false positive paren warning

https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00186.html
	PR c++/82710
	* decl.c (grokdeclarator): Protect MAYBE_CLASS things from paren
	warning too.

	PR c++/82710
	* g++.dg/warn/pr82710.C: More cases.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/warn/pr82710.C