[Bug c++/24795] New: [4.1 Regression] Error in dependent name-lookup

rguenth at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Nov 11 14:28:00 GMT 2005


Consider the following testcase, where the call to foo(B&) should be resolved
at template instantiaton time of the function template g.

struct A {};
struct B {};

void foo(A&);

template <class T>
void g(T& t)
{
  foo(t);
}

void foo(B&);

void bar(B& b)
{
  g(b);
}

This works correctly.  Now add some namespace blurb (which shouldn't really
change anything here) and get

namespace X {
struct A {};
struct B {};
}

void foo(X::A&);

template <class T>
void g(T& t)
{
  foo(t);
}

void foo(X::B&);

void bar(X::B& b)
{
  g(b);
}

where 4.1 now rejects this with
t2.C: In function ‘void g(T&) [with T = X::B]’:
t2.C:18:   instantiated from here
t2.C:11: error: invalid initialization of reference of type ‘X::A&’ from
expression of type ‘X::B’
t2.C:6: error: in passing argument 1 of ‘void foo(X::A&)’

even more funny, adding an unrelated overload of foo:

namespace X {
struct A {};
struct B {};
struct C {};
}

void foo(X::A&);
void foo(X::C&);

template <class T>
void g(T& t)
{
  foo(t);
}

void foo(X::B&);

void bar(X::B& b)
{
  g(b);
}

we reject it with
t3.C: In function ‘void g(T&) [with T = X::B]’:
t3.C:20:   instantiated from here
t3.C:13: error: no matching function for call to ‘foo(X::B&)’
t3.C:7: note: candidates are: void foo(X::A&)
t3.C:8: note:                 void foo(X::C&)


EDG rejects the latter two with a consistent error message (in -strict_ansi
mode):
t3.C(13): error: no instance of overloaded function "foo" matches the argument
list
            argument types are: (X::B)
    foo(t);
    ^
          detected during instantiation of "void g(T &) [with T=X::B]" 

compilation aborted for t3.C (code 2)


g++ accepts even the following, which may hint at the reason for the
inconsistent error messages?

namespace X {
struct B {};
}

template <class T>
void g(T& t)
{
  foo(t);
}

void foo(X::B&);

void bar(X::B& b)
{
  g(b);
}


I'm really unsure who's at fault here and if this is rejects-valid or
rejects-invalid.  Digging in the standard now, but maybe someone can
point me at the relevant section.


-- 
           Summary: [4.1 Regression] Error in dependent name-lookup
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list