public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class
@ 2010-11-30 19:15 schaub-johannes at web dot de
  2010-11-30 19:22 ` [Bug c++/46731] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: schaub-johannes at web dot de @ 2010-11-30 19:15 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: GCC shouts "cannot call member function 'void a::g()'
                    without object" if a is a dependent base class
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub-johannes@web.de


This code should compile just fine, but it fails with GCC

struct a { 
  void g() { }
  template<typename T> 
  struct b : T { void f() { g(); } }; 
};

void f() {
  a::b<a> x;
  x.f();
}

[js@HOST2 cpp]$ LC_ALL=C g++ main1.cpp
main1.cpp: In member function 'void a::b<T>::f() [with T = a]':
main1.cpp:9:7:   instantiated from here
main1.cpp:4:29: error: cannot call member function 'void a::g()' without object

The reason for its validity has been discussed at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21008 and
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#515 .


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

* [Bug c++/46731] GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class
  2010-11-30 19:15 [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class schaub-johannes at web dot de
@ 2010-11-30 19:22 ` pinskia at gcc dot gnu.org
  2010-11-30 19:45 ` schaub-johannes at web dot de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-11-30 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-30 19:15:23 UTC ---
Actually it is not valid but for a different reason than what GCC gives.  See
PR 24163, and PR 15272 for the reasons why g() should not be found when doing
the lookup.


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

* [Bug c++/46731] GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class
  2010-11-30 19:15 [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class schaub-johannes at web dot de
  2010-11-30 19:22 ` [Bug c++/46731] " pinskia at gcc dot gnu.org
@ 2010-11-30 19:45 ` schaub-johannes at web dot de
  2010-12-01 13:52 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schaub-johannes at web dot de @ 2010-11-30 19:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Johannes Schaub <schaub-johannes at web dot de> 2010-11-30 19:21:57 UTC ---
(In reply to comment #1)
> Actually it is not valid but for a different reason than what GCC gives.  See
> PR 24163, and PR 15272 for the reasons why g() should not be found when doing
> the lookup.

"g" is not found by looking into the base, but by doing unqualified lookup in
the lexically enclosing nesting class scope "a". This way "g" is still found,
even though the dependent base class isn't looked into.


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

* [Bug c++/46731] GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class
  2010-11-30 19:15 [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class schaub-johannes at web dot de
  2010-11-30 19:22 ` [Bug c++/46731] " pinskia at gcc dot gnu.org
  2010-11-30 19:45 ` schaub-johannes at web dot de
@ 2010-12-01 13:52 ` rguenth at gcc dot gnu.org
  2010-12-01 14:19 ` redi at gcc dot gnu.org
  2010-12-01 14:39 ` schaub-johannes at web dot de
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-12-01 13:52 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.12.01 13:52:15
     Ever Confirmed|0                           |1

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-12-01 13:52:15 UTC ---
Confirmed.  EDG accepts it.

But I would argue that g is bound at first stage name-lookup
and thus it is not a dependent name and thus the error is correct.


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

* [Bug c++/46731] GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class
  2010-11-30 19:15 [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class schaub-johannes at web dot de
                   ` (2 preceding siblings ...)
  2010-12-01 13:52 ` rguenth at gcc dot gnu.org
@ 2010-12-01 14:19 ` redi at gcc dot gnu.org
  2010-12-01 14:39 ` schaub-johannes at web dot de
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2010-12-01 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-12-01 14:18:55 UTC ---
(In reply to comment #3)
> But I would argue that g is bound at first stage name-lookup
> and thus it is not a dependent name and thus the error is correct.

9.3.1p3 says that because it's found in the enclosing scope (during phase one)
it should be transformed into (*this).g() and so it's not called without an
object.

It's ill-formed for any specialisation b<T> where T is not a or some class
deriving from a, but for b<a> it's well-formed.


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

* [Bug c++/46731] GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class
  2010-11-30 19:15 [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class schaub-johannes at web dot de
                   ` (3 preceding siblings ...)
  2010-12-01 14:19 ` redi at gcc dot gnu.org
@ 2010-12-01 14:39 ` schaub-johannes at web dot de
  4 siblings, 0 replies; 6+ messages in thread
From: schaub-johannes at web dot de @ 2010-12-01 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Johannes Schaub <schaub-johannes at web dot de> 2010-12-01 14:39:18 UTC ---
(In reply to comment #3)
> Confirmed.  EDG accepts it.
> 
> But I would argue that g is bound at first stage name-lookup
> and thus it is not a dependent name and thus the error is correct.

It is bound at first stage name lookup because it's not a dependent name. Thus,
it is transformed to class-member access because "g" is a non-static member of
some class.

It being bound at first stage name lookup doesn't IMO mean that you drop any
analysis that would depend on instantiation semantics, it just means you do
name lookup only in the definition as opposed to be in the instantiation. In
this case what will happen:

  g -> (*this).g  // found g in the definition context!
  -> (*this).g();

So, you have an implicit object parameter of type a&, and an implied object
argument of lvalue of type "b<a>", that has a dependent base class. The
validity of the call depends on template arguments, so you have to delay
further analysis. This further analysis doesn't have to do with name lookup but
with overload resolution.

The committee clarified the issue by resolving DR 515, stating their intent to
support this and similar code. It may require that you internally mark
constructs as "instantiation dependent" that formally aren't marked as
type/value dependent, just because its validity depends on facts you can only
know when instatiating so that you know when walking over the AST top-down what
you again need to check and what not. I've no idea about those internal
compiler things. Active issue #1172 looks for proper wording to capture any
such constructs in a formal way.


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

end of thread, other threads:[~2010-12-01 14:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-30 19:15 [Bug c++/46731] New: GCC shouts "cannot call member function 'void a::g()' without object" if a is a dependent base class schaub-johannes at web dot de
2010-11-30 19:22 ` [Bug c++/46731] " pinskia at gcc dot gnu.org
2010-11-30 19:45 ` schaub-johannes at web dot de
2010-12-01 13:52 ` rguenth at gcc dot gnu.org
2010-12-01 14:19 ` redi at gcc dot gnu.org
2010-12-01 14:39 ` schaub-johannes at web dot de

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).