From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18828 invoked by alias); 13 Oct 2009 00:31:48 -0000 Received: (qmail 18802 invoked by uid 48); 13 Oct 2009 00:31:36 -0000 Date: Tue, 13 Oct 2009 00:31:00 -0000 Subject: [Bug c++/41690] New: Scoping is incorrect for inherited classes nested inside a templated class. X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "timothy dot renner at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-10/txt/msg01083.txt.bz2 When a nested class inherits from another nested class, scoping is incorrect only if the outer class is templated. A full .ii file follows, but to illustrate in a compact example: class A { class B { protected: int d_data; }; class C : public B { void foo() { d_data = 0; } }; }; If A is *not* templated, the code will compile. If A is templated, the compiler complains that d_data has not been declared in the current scope. There is no option for attaching files, so the .ii file follows: --------------------------%<---------------------------------------- # 1 "a.cpp" # 1 "" # 1 "" # 1 "a.cpp" # 1 "templ.h" 1 class notempl { private: int d_stuff; class A { protected: int d_data; }; class B : public A { void test() { d_data = 0; } }; }; template class templ { private: int d_stuff; class A { protected: int d_data; }; class B : public A { void test() { d_data = 0; } }; }; # 2 "a.cpp" 2 int main() { notempl tmp1; templ tmp2; return 0; } --------------------------%<---------------------------------------- Detailed compilation follows: ~/tmp/gcc-bug# g++ -v -save-temps a.cpp Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.3.3/cc1plus -E -quiet -v -D_GNU_SOURCE a.cpp -D_FORTIFY_SOURCE=2 -mtune=generic -fpch-preprocess -o a.ii ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/usr/include/x86_64-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.3 /usr/include/c++/4.3/x86_64-linux-gnu /usr/include/c++/4.3/backward /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.3.3/include /usr/lib/gcc/x86_64-linux-gnu/4.3.3/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.3.3/cc1plus -fpreprocessed a.ii -quiet -dumpbase a.cpp -mtune=generic -auxbase a -version -fstack-protector -o a.s GNU C++ (Ubuntu 4.3.3-5ubuntu4) version 4.3.3 (x86_64-linux-gnu) compiled by GNU C version 4.3.3, GMP version 4.2.4, MPFR version 2.4.0. GGC heuristics: --param ggc-min-expand=97 --param ggc-min-heapsize=126404 Compiler executable checksum: d9dd67dcc191271ac69fd2c05266cf9c In file included from a.cpp:2: templ.h: In member function void templ::B::test(): templ.h:31: error: d_data was not declared in this scope -- Summary: Scoping is incorrect for inherited classes nested inside a templated class. Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: timothy dot renner at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41690