Bug 27787 - Qualified lookup fails to find inherited class template
Summary: Qualified lookup fails to find inherited class template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.1.2
Assignee: Nathan Sidwell
URL:
Keywords: rejects-valid
Depends on: 9634
Blocks: 25868 30818
  Show dependency treegraph
 
Reported: 2006-05-28 18:21 UTC by Tobias Schwinger
Modified: 2007-04-23 22:29 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3 3.2.3 4.1.2
Known to fail: 3.4.3 4.1.0
Last reconfirmed: 2006-08-25 09:53:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Schwinger 2006-05-28 18:21:02 UTC
// 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);
};
Comment 1 Andrew Pinski 2006-05-28 18:42:59 UTC
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).
Comment 2 Andrew Pinski 2006-05-28 18:43:52 UTC
Replacing a with x<A>, makes this work.
Comment 3 Andrew Pinski 2006-05-28 18:51:13 UTC
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.
Comment 4 Tobias Schwinger 2006-05-28 21:47:53 UTC
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

Comment 5 Wolfgang Bangerth 2006-08-06 22:16:30 UTC
Confirmed. I'm sure this is a duplicate of some other PR, but I don't
know which one right now...

W.
Comment 6 Nathan Sidwell 2006-08-25 16:52:44 UTC
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.
Comment 7 Nathan Sidwell 2006-08-25 16:56:16 UTC
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

Comment 8 Richard Biener 2006-10-18 09:18:17 UTC
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

Comment 9 Andrew Pinski 2006-10-27 01:26:08 UTC
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.