// The code has been tested with GCC 3.4.2, 4.1.1 and 4.2.0 (alpha) and fails. // It compiles successfully with Comeau (>= 4.2) and VisualC++ (>=7.1). template<typename X> struct x { template<typename Y> struct y { typedef Y type; }; }; template<typename A> struct a : x<A> { // supposed to fail (unqualified lookup does not look into dependent base) // [ 14.6.2-3 ] // // template<typename B> // typename y<B>::type f(B); // // qualified lookup should find inherited class template 'y', however template<typename B> typename a::template y<B>::type f(B); };
There is a defect report about this if a is really a dependent name or not (or maybe it is the one about inherite and template and name lookup I forget).
Replacing a with x<A>, makes this work.
http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#213 And http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#108 Both seems a way to better understand this but I am confused with what the standard says with these two defect reports.
It seems my report is missing some detail. Here's my apology and an attempt to outline my standard interpretation that makes me think it is a bug. (In reply to comment #0) > > template<typename X> > struct x > { > template<typename Y> > struct y > { > typedef Y type; > }; > }; > > template<typename A> > struct a : x<A> > { > // template<typename B> > // typename y<B>::type f(B); // ill-formed - the base class 'x<A>' is obviously dependent (since it depends on 'A'), so GCC validly detects an ill-formed program trying to find 'y' (and so does Comeau) > // qualified lookup should find inherited class template 'y', however > template<typename B> > typename a::template y<B>::type f(B); - the injected class name 'a' refers to the class template specialization (same as 'a<A>' in this context) and should be found even by unqualified lookup (works correctly, so far) - qualified lookup applies to 'template y' because it's qualified by 'a', 14.6.2-3 only applies to unqualified lookup so there is no reason for 'template y' not to be found
Confirmed. I'm sure this is a duplicate of some other PR, but I don't know which one right now... W.
2006-08-25 Nathan Sidwell <nathan@codesourcery.com> PR c++/27787 * decl.c (make_typename_type): Only try and resolve it when context is not dependent. Refactor. * decl2.c (check_classfn): Push to class scope before looking for the function.
Subject: Bug 27787 Author: nathan Date: Fri Aug 25 16:56:07 2006 New Revision: 116409 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116409 Log: cp/ PR c++/27787 * decl.c (make_typename_type): Only try and resolve it when context is not dependent. Refactor. * decl2.c (check_classfn): Push to class scope before looking for the function. testsuite/ PR c++/27787 * g++.dg/template/typename10.C: New. * g++.dg/template/lookup4.C: Remove bogus error marker. Added: trunk/gcc/testsuite/g++.dg/template/typename10.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/cp/decl2.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/template/lookup4.C
Subject: Bug 27787 Author: rguenth Date: Wed Oct 18 09:18:07 2006 New Revision: 117852 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117852 Log: 2006-10-18 Richard Guenther <rguenther@suse.de> PR C++/25878 Backport from mainline: 2006-08-25 Nathan Sidwell <nathan@codesourcery.com> PR c++/27787 * decl.c (make_typename_type): Only try and resolve it when context is not dependent. Refactor. * decl2.c (check_classfn): Push to class scope before looking * for the function. * g++.dg/template/typename10.C: New. * g++.dg/template/lookup4.C: Remove bogus error marker. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/typename10.C - copied unchanged from r116409, trunk/gcc/testsuite/g++.dg/template/typename10.C Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/decl.c branches/gcc-4_1-branch/gcc/cp/decl2.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/lookup4.C
Actually I think this is the same as DR 224 which says "a" here is not dependent but shown by PR 29469 comment #5, that DR report is bogus.