c++/8050: g++ instantiates template too late

marc@mit.edu marc@mit.edu
Wed Sep 25 19:36:00 GMT 2002


>Number:         8050
>Category:       c++
>Synopsis:       g++ instantiates template too late
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 25 16:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Marc Horowitz
>Release:        unknown-1.0
>Organization:
>Environment:
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)
>Description:
g++ gives an error on valid code.  I believe the problem
has to do with when templates are instantiated and available
to the compiler, but it is difficult to be certain.

I first observed this with the compiler listed in the
Environment field above, but have confirmed it exists
in 3.0.3 and 3.1.  It does not exist in 2.95.3 or 2.95.4.
I do not have access to 3.2, or any snapshots.
>How-To-Repeat:
Compile this code:

template <class T>
class X
{
public:
    operator T*() { return(0); }
};

int* p;
extern X<int> xp;

void foo()
{

    p == xp;
    xp == p;

    p == xp;
}

with this command line:

g++ -c foo.cc

You will get this error:

cfp.cc: In function `void foo ()':
cfp.cc:14: no match for `int *& == X<int> &'

If you reorder the lines in foo() so that line 15 is first,
the compiler does not complain anymore.
>Fix:
Unknown.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list