c++/9558: subclass cannot find parent members without explicit "this->" in some cases

ryan@epicgames.com ryan@epicgames.com
Mon Feb 3 23:36:00 GMT 2003

>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
>Originator:     ryan@epicgames.com
>Release:        unknown-1.0

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
    A() {}
    int important_value;

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

int main(void)
    B<int> x();

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



Compile the example file. Result is consistent in CVS from about 12 hours ago (february 2nd, 2003).

I have none at this time.


More information about the Gcc-bugs mailing list