Bug 9783 - [DR433] Can't forward reference class in argument to templated method.
Summary: [DR433] Can't forward reference class in argument to templated method.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 4.1.0
Assignee: Kriang Lerdsuwanakij
URL:
Keywords: patch, rejects-valid
Depends on: 4403
Blocks: c++-lookup, c++-name-lookup
  Show dependency treegraph
 
Reported: 2003-02-20 23:26 UTC by mleone
Modified: 2005-03-14 14:54 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-05-05 03:49:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mleone 2003-02-20 23:26:00 UTC
The following fails to compile.  Workaround is to declare forward reference to class outside the template.

template<class Info>
class Table {
  public:
    bool Lookup(int name, class Detail* detail, Info* info) const;
    void Insert(int name, class Detail* detail, Info  info);
};

class Detail {
  public:
    int stuff;
};

template<class Info>
bool Table<Info>::Lookup(int name, Detail* detail, Info* info) const {
    return true;
}

template<class Info>
void Table<Info>::Insert(int name, Detail* detail, Info info) {
}

Release:
g++ 3.2

Environment:
RedHat 7.2, i686 multiprocessor
Comment 1 Wolfgang Bangerth 2003-02-20 23:57:45 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. Here's a simpler testcase:
    --------------------------
    template <typename T>
    struct C {
        void foo (struct X *);
    };
    
    struct X {};
    
    template <typename T>
    void C<T>::foo(struct X *) {}
    -------------------------------
    It's rejected by all versions of gcc. However, if
    one makes C a non-template, then it is accepted. Strange.
    
    I suspect that the language actually mandates this behavior,
    since both icc and cxx (well, both EDG based after all)
    have this behavior as well. I don't know what is right in
    this case.
    
    W.
Comment 2 Kriang Lerdsuwanakij 2004-12-02 12:39:17 UTC
This should be allowed according to DR433.
Comment 3 Kriang Lerdsuwanakij 2004-12-30 07:38:57 UTC
Patch for PR4403 also includes a fix to this bug
(the while-loop hunk in pushtag).
Comment 4 Kriang Lerdsuwanakij 2005-03-13 16:48:19 UTC
Patch submitted:
  http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01294.html
Comment 5 GCC Commits 2005-03-14 14:52:23 UTC
Subject: Bug 9783

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	lerdsuwa@gcc.gnu.org	2005-03-14 14:51:25

Modified files:
	gcc/cp         : ChangeLog name-lookup.c pt.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.pt: inherit2.C 
Added files:
	gcc/testsuite/g++.dg/template: friend34.C friend35.C 

Log message:
	PR c++/4403
	PR c++/9783, DR433
	* name-lookup.c (pushtag): Skip template parameter scope when
	scope is ts_global.  Don't push tag into template parameter
	scope.
	* pt.c (instantiate_class_template): Reorder friend class
	template substitution to handle non-dependent friend class
	that hasn't been previously declared.
	
	* g++.dg/template/friend34.C: New test.
	* g++.dg/template/friend35.C: Likewise.
	* g++.old-deja/g++.pt/inherit2.C: Remove XFAIL's.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4662&r2=1.4663
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.112&r2=1.113
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.983&r2=1.984
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5161&r2=1.5162
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend34.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend35.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/inherit2.C.diff?cvsroot=gcc&r1=1.7&r2=1.8

Comment 6 Kriang Lerdsuwanakij 2005-03-14 14:54:33 UTC
Fixed in the mainline.