public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17459] Spurious message when forgetting parentheses on call of member
       [not found] <bug-17459-4@http.gcc.gnu.org/bugzilla/>
@ 2013-05-16 17:26 ` manu at gcc dot gnu.org
  2021-07-15 20:38 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2013-05-16 17:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17459

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Paolo Carlini from comment #4)
> Manuel can you help me reassessing this? I think we are doing much better.

I get this:

test.cc:3:19: error: invalid use of non-static member function
   void bar() { foo; } 
                   ^
 void S::bar3()
test.cc:5:18: error: ISO C++ forbids taking the address of an unqualified or
parenthesized non-static member function to form a pointer to member function. 
Say ‘&S::foo’ [-fpermissive]
   void bar3() { &foo; } 
                  ^
 void* S::bar2()
test.cc:6:26: error: cannot convert ‘S::foo’ from type ‘void (S::)()’ to type
‘void*’
   void * bar2() { return foo; }
                          ^

The first error could be a bit nicer if it said why it is invalid. Clang does:

test.cc:3:16: error: reference to non-static member function must be called;
did you mean to call it with no arguments?

but the thing is that this is not even a valid reference, so the error could
clarify a bit more the problem, no?

ISO C++ forbids taking the address of an unqualified non-static member
function, say ‘&S::foo’ instead; or did you mean to call 'foo()'?

The last error is bogus, it should be the same as the first one. Clang gives
two errors, but at least the first is the correct one:

test.cc:6:26: error: reference to non-static member function must be called;
did you mean to call it with no arguments?
  void * bar2() { return foo; }
                         ^~~
                            ()
test.cc:6:26: error: cannot initialize return object of type 'void *' with an
rvalue of type 'void'
  void * bar2() { return foo; }
                         ^~~~
>From gcc-bugs-return-422461-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu May 16 18:00:13 2013
Return-Path: <gcc-bugs-return-422461-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21524 invoked by alias); 16 May 2013 18:00:13 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 21365 invoked by uid 48); 16 May 2013 18:00:03 -0000
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/57303] [4.7/4.8/4.9 Regression] struct miscompiled at -O1 and above
Date: Thu, 16 May 2013 18:00:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: hjl.tools at gmail dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57303-4-fJlbMWvQeS@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57303-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57303-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-05/txt/msg01134.txt.bz2
Content-length: 199

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW303

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
It is caused by revision 170984:

http://gcc.gnu.org/ml/gcc-cvs/2011-03/msg00405.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/17459] Spurious message when forgetting parentheses on call of member
       [not found] <bug-17459-4@http.gcc.gnu.org/bugzilla/>
  2013-05-16 17:26 ` [Bug c++/17459] Spurious message when forgetting parentheses on call of member manu at gcc dot gnu.org
@ 2021-07-15 20:38 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-15 20:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17459

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-06-13 00:43:47         |2021-7-15

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Manuel López-Ibáñez from comment #5)
> The first error could be a bit nicer if it said why it is invalid. Clang
> does:
> 
> test.cc:3:16: error: reference to non-static member function must be called;
> did you mean to call it with no arguments?

I think we should just add a fix-it hint suggesting to add the ()


> but the thing is that this is not even a valid reference, so the error could
> clarify a bit more the problem, no?

I don't think mentioning "reference" here is a good idea at all, because that
means something specific in C++ (and completely unrelated to this).

I prefer GCC's "invalid use" wording. With a fix-it to add the () the error
would be fine.

If the function can't be called with no arguments, the fix-it would be wrong.
I'm not sure what we want to do in that case. Suggest the fix-it anyway, and
let the user figure out the next step?

Clang just says:

17459-c3.C:3:16: error: reference to non-static member function must be called

i.e. it omits the "did you mean to call it with no arguments?" part. So we
could do the same and just not provide a fix-it in that case.


> ISO C++ forbids taking the address of an unqualified non-static member
> function, say ‘&S::foo’ instead; or did you mean to call 'foo()'?

Maybe we should remove the -fpermissive extension that allows &foo as a
non-standard way to form a pointer-to-member. That simplifies the handling of
&foo, because we can just reject it instead of using a permerror. It's more
than 20 years since that was acceptable syntax.

And that could use a fix-it hint too, to suggest turning &foo into &S::foo.


> The last error is bogus, it should be the same as the first one.

Agreed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/17459] Spurious message when forgetting parentheses on call of member
       [not found] <bug-17459-102@http.gcc.gnu.org/bugzilla/>
@ 2010-02-21 19:08 ` manu at gcc dot gnu dot org
  0 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21 19:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2010-02-21 19:07 -------
More weirdeness.

// PR c++/17459: Spurious message when forgetting parentheses on call of member
// { dg-do compile }
struct S {
  void foo();
  void bar() { foo; } // { dg-error "statement cannot resolve address of
overloaded function" }
  // { dg-message "note: taking the address of a member function requires the
syntax '&S::foo'" "" { target *-*-* } 5 }
  void bar3() { &foo; } // { dg-error "ISO C.. forbids taking the address" }
  void * bar2() { return foo; }
};


This testcase produces:

pr17459.C: In member function 'void S::bar()':
pr17459.C:5:19: error: statement cannot resolve address of overloaded function
pr17459.C:5:19: note: taking the address of a member function requires the
syntax '&S::foo'
pr17459.C: In member function 'void S::bar3()':
pr17459.C:7:18: error: ISO C++ forbids taking the address of an unqualified or
parenthesized non-static member function to form a pointer to member function. 
Say '&S::f\
oo'
pr17459.C: In member function 'void* S::bar2()':
pr17459.C:8:26: error: argument of type 'void (S::)()' does not match 'void*'


The last one really kills me. It should be the same error as the first one,
isn't it? 

Oh, I give up on this one!


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17459


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/17459] Spurious message when forgetting parentheses on call of member
  2004-09-13 14:20 [Bug c++/17459] New: " bangerth at dealii dot org
  2004-09-13 17:33 ` [Bug c++/17459] " giovannibajo at libero dot it
@ 2004-09-13 18:32 ` bangerth at dealii dot org
  1 sibling, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-09-13 18:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-09-13 18:32 -------
Uhm, yes... I tend to take icc's acceptance as standards conformance  
sometimes :-( 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-09-13 18:32:41
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17459


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/17459] Spurious message when forgetting parentheses on call of member
  2004-09-13 14:20 [Bug c++/17459] New: " bangerth at dealii dot org
@ 2004-09-13 17:33 ` giovannibajo at libero dot it
  2004-09-13 18:32 ` bangerth at dealii dot org
  1 sibling, 0 replies; 5+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-13 17:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-09-13 17:33 -------
Notice that you need "&S::foo" to take the address of a member function. The 
syntax "foo(blah)" is the function call syntax, and it is available only for 
function calls.

I am not sure why EDG accepts it. Anyway, our diagnostic is suboptimal.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17459


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-15 20:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-17459-4@http.gcc.gnu.org/bugzilla/>
2013-05-16 17:26 ` [Bug c++/17459] Spurious message when forgetting parentheses on call of member manu at gcc dot gnu.org
2021-07-15 20:38 ` redi at gcc dot gnu.org
     [not found] <bug-17459-102@http.gcc.gnu.org/bugzilla/>
2010-02-21 19:08 ` manu at gcc dot gnu dot org
2004-09-13 14:20 [Bug c++/17459] New: " bangerth at dealii dot org
2004-09-13 17:33 ` [Bug c++/17459] " giovannibajo at libero dot it
2004-09-13 18:32 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).