This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16635] g++ instantiates templates at the wrong place



------- Comment #10 from andrew dot stubbs at st dot com  2007-05-31 10:57 -------
Here's another issue in this area. Is it the same, or a separate bug? This code
is adapted from the example in DR197.

#include <stdio.h>

struct C1 {};
struct C2 : C1 {
};

C1 c1;
C2 c2;

    void f(C1);

    template <class T> void g(T t)
    {
        f(c2);  // f(C1) should be the nearest match
        f(t);   // dependent
    }

    void f(C2);

    int main()
    {
        g(c2);       // will cause one call of f(C1) followed
                     // by one calls of f(C2)
        g(c1);      // will cause two calls of f(C1)
    }

void f(C1) { printf ("C1\n");}
void f(C2) { printf ("C2\n");}

What actually happens (with the 4.1.1 I have anyway) is three calls to f(C2)
followed by one call to f(C1). This shows that the *non-dependent* call is
being resolved in the wrong scope also - it should not be able to see f(C2).

If the prototype for f(C2) is removed, then the previously described problem is
apparent also, and the (incorrect) behaviour of the program is unchanged.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16635


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]