public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/9558: subclass cannot find parent members without explicit "this->" in some cases
@ 2003-02-03 23:45 bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: bangerth @ 2003-02-03 23:45 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, ryan

Synopsis: subclass cannot find parent members without explicit "this->" in some cases

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Mon Feb  3 23:45:09 2003
State-Changed-Why:
    That's how C++ works -- it's a feature, not a bug, and
    it's called two-stage (or dependent) name lookup.
    
    We really need to get an entry into the non-bugs page about
    this, we are getting far too many reports about this...
    
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9558


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

* Re: c++/9558: subclass cannot find parent members without explicit "this->" in some cases
@ 2003-02-04  2:46 Wolfgang Bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Bangerth @ 2003-02-04  2:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/9558; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: "Ryan C. Gordon" <ryan@epicgames.com>
Cc: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>, <mark@codesourcery.com>
Subject: Re: c++/9558: subclass cannot find parent members without explicit
 "this->" in some cases
Date: Mon, 3 Feb 2003 20:43:26 -0600 (CST)

 > After thinking about it, (and based on the initial response of "can we 
 > add this as a FAQ to non-bugs"), 
 
 ...which I just took care of...
 
 > perhaps the problem is in the error 
 > message more than the behaviour. My assumption was this was a problem in 
 > the new parser and that it wasn't resolving because something had 
 > confused it. Is there a way to differentiate between this and a variable 
 > that absolutely positively does not exist, and issue a different error 
 > message? I think that would at least stop more incorrect bug reports on 
 > the issue.
 
 It's hard to come up with something reasonable, because of cases like
 
   template <typename T> struct A        { int i;               };
   template <typename T> struct B : A<T> { int f() {return i;}  };
   template <>           struct A<int>   {                      }; // oops
 
 In B::f, what is the compiler supposed to tell you? I guess one would like 
 to have something like
   Error: "i" undeclared (did you mean "this->i" or A<T>::i"?)
 
 The gotcha comes in the specialization of A<int>: there really is no "i" 
 in this class.
 
 There are worse cases, like 
   template <typename T> struct B : typename A<T>::some_typedef {...};
 where you really have no idea what the base class might be, unless you 
 actually instantiate it.
 
 Of course, this doesn't mean that Mark or someone else has ingeneous ideas 
 for warnings...
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth/
 
 


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

* Re: c++/9558: subclass cannot find parent members without explicit "this->" in some cases
@ 2003-02-04  2:36 Ryan C. Gordon
  0 siblings, 0 replies; 6+ messages in thread
From: Ryan C. Gordon @ 2003-02-04  2:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/9558; it has been noted by GNATS.

From: "Ryan C. Gordon" <ryan@epicgames.com>
To: Wolfgang Bangerth <bangerth@ticam.utexas.edu>, gcc-bugs@gcc.gnu.org,
   gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c++/9558: subclass cannot find parent members without explicit
 "this->" in some cases
Date: Mon, 03 Feb 2003 21:26:26 -0500

 > So, what is right and what is wrong? And what is the "real world" you 
 > quote?
 
 Okay, I'll grant that.  :)
 
 After thinking about it, (and based on the initial response of "can we 
 add this as a FAQ to non-bugs"), perhaps the problem is in the error 
 message more than the behaviour. My assumption was this was a problem in 
 the new parser and that it wasn't resolving because something had 
 confused it. Is there a way to differentiate between this and a variable 
 that absolutely positively does not exist, and issue a different error 
 message? I think that would at least stop more incorrect bug reports on 
 the issue.
 
 At either rate, sorry to waste your time on this...I'll try to be a 
 little more researched in the future.
 
 --ryan.
 
 


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

* Re: c++/9558: subclass cannot find parent members without explicit "this->" in some cases
@ 2003-02-04  0:56 Wolfgang Bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Bangerth @ 2003-02-04  0:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/9558; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: "Ryan C. Gordon" <ryan@epicgames.com>
Cc: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
Subject: Re: c++/9558: subclass cannot find parent members without explicit
 "this->" in some cases
Date: Mon, 3 Feb 2003 18:48:50 -0600 (CST)

 > Surely there's got to be some consideration for backwards compatibility, 
 > if not real world issues?
 
 Just to prove my point about surprising behavior:
 -----------------------------------------------
 #include <iostream>
 // ---------
 const int N = 2;
 
 // ---------
 template <typename T> struct A {    // templated base class
     static const int N = 1;
 };
 template <typename T> struct B : A<T> {
     B () { std::cout << "N=" << N << std::endl; }
 };
 
 // ---------
 
 struct C {    // non-templated base class
     static const int N = 1;
 };
 template <typename T> struct D : C {
     D () { std::cout << "N=" << N << std::endl; }
 };
 
 // ---------
 
 int main () {
   B<int> b;
   D<int> d;
 }
 ---------------------------------------------
 
 In each case, the question is: which N to take, the one from the base 
 class, or the global one. Here are a couple of data points:
 
 gcc2.96:
 N=2
 N=1
 
 present gcc CVS:
 N=2
 N=1
 
 Intel icc7:
 N=1
 N=1
 
 Intel icc7 with -Xc -ansi:
 N=2
 N=1
 
 Compaq cxx:
 N=1
 N=1
 
 So, what is right and what is wrong? And what is the "real world" you 
 quote?
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth/
 
 


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

* Re: c++/9558: subclass cannot find parent members without explicit "this->" in some cases
@ 2003-02-04  0:26 Wolfgang Bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Bangerth @ 2003-02-04  0:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/9558; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: "Ryan C. Gordon" <ryan@epicgames.com>
Cc: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
Subject: Re: c++/9558: subclass cannot find parent members without explicit
 "this->" in some cases
Date: Mon, 3 Feb 2003 18:21:52 -0600 (CST)

 > If that's how C++ works in the official spec, it's not how it works in 
 > real life.
 
 I think we all understand this, but this is just so because compilers 
 previously didn't implement the standard correctly and did not _force_ you 
 to write compliant code. Mark et al dared to do so in the new parser.
 
 
 > I've got half a million lines of code in Unreal Tournament 2003 that 
 > this "feature" breaks, which compile fine on everything from CodeWarrior 
 > to Intel's compiler to Visual C to GCC 2.95.3, 3.1, and 3.2. I can list 
 > at least five other games I've worked on that this breaks. I do not 
 > control or write this code, I just port it.
 
 gcc 2.95 ... 3.2 accept it, but just because they don't implement the 
 standard.
 
 Intel icc accepts it, unless for example you switch on -Xc -ansi. If you 
 do so, then it won't accept your code either. AFAIK, the same holds for 
 HP's aCC.
 
 The situation might be worse than you think: if two-stage name lookup is 
 not implemented, then you might get wrong results sometimes. So you have 
 to decide whether you implement the standard or the old status quo.
 
 
 > Surely there's got to be some consideration for backwards compatibility, 
 > if not real world issues?
 
 I think the answer will be: if you want to use a newer compiler, fix your 
 code. I fixed my 250k lines of code, which was painful admittedly, but I 
 think it's necessary.
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth/
 
 


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

* c++/9558: subclass cannot find parent members without explicit "this->" in some cases
@ 2003-02-03 23:36 ryan
  0 siblings, 0 replies; 6+ messages in thread
From: ryan @ 2003-02-03 23:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9558
>Category:       c++
>Synopsis:       subclass cannot find parent members without explicit "this->" in some cases
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 03 23:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     ryan@epicgames.com
>Release:        unknown-1.0
>Organization:
>Environment:

>Description:
As this is a 23-line test case with no #includes, it'll speak best for itself, but I'll comment afterwards.

...here's the preprocessed source:

# 1 "x.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "x.cpp"

template< class T > class A
{
public:
    A() {}
    int important_value;
};

template< class T > class B : public A<T>
{
public:
    B() : A<T>()
    {
        this->important_value = 10;
        important_value = 10;
    }
};

int main(void)
{
    B<int> x();
    return(0);
}


...and here is the -v -save-temps output:

[icculus@wickedsick ~]$ gcc -v -save-temps -o x ./x.cpp
Reading specs from /usr/local/gcc-cvs/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs
Configured with: ../gcc/configure --prefix=/usr/local/gcc-cvs
Thread model: posix
gcc version 3.4 20030203 (experimental)
 /usr/local/gcc-cvs/lib/gcc-lib/i686-pc-linux-gnu/3.4/cc1plus -E -D__GNUG__=3 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=4 -D__GNUC_PATCHLEVEL__=0 -D_GNU_SOURCE ./x.cpp x.ii
ignoring nonexistent directory "/usr/local/gcc-cvs/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-cvs/include/c++/3.4
 /usr/local/gcc-cvs/include/c++/3.4/i686-pc-linux-gnu
 /usr/local/gcc-cvs/include/c++/3.4/backward
 /usr/local/include
 /usr/local/gcc-cvs/include
 /usr/local/gcc-cvs/lib/gcc-lib/i686-pc-linux-gnu/3.4/include
 /usr/include
End of search list.
 /usr/local/gcc-cvs/lib/gcc-lib/i686-pc-linux-gnu/3.4/cc1plus -fpreprocessed x.ii -quiet -dumpbase x.cpp -auxbase x -version -o x.s
GNU C++ version 3.4 20030203 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 2.95.3 20010315 (release).
x.cpp: In constructor `B<T>::B()':
x.cpp:15: error: `important_value' has not been declared



The important part is B::B()'s assignments to "important_value". This gives an incorrect error stating that the member is not declared unless specifically prepended with "this->".

More notes: if "A" is not a template, or it uses a explicit type ("A<int>" instead of, "A<T>"), this error goes away, too. I assume this is just a minor detail in the new recursive-descent parser, but I'll leave real analysis to the experts.  :)

Thanks!

--ryan.

>How-To-Repeat:
Compile the example file. Result is consistent in CVS from about 12 hours ago (february 2nd, 2003).

>Fix:
I have none at this time.

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2003-02-04  2:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-03 23:45 c++/9558: subclass cannot find parent members without explicit "this->" in some cases bangerth
  -- strict thread matches above, loose matches on Subject: below --
2003-02-04  2:46 Wolfgang Bangerth
2003-02-04  2:36 Ryan C. Gordon
2003-02-04  0:56 Wolfgang Bangerth
2003-02-04  0:26 Wolfgang Bangerth
2003-02-03 23:36 ryan

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