[cfe-dev] Error name lookup in template dependant base class

Adrien Chauve adrien.chauve at gmail.com
Fri Dec 3 12:52:49 PST 2010


Hi,

I'm trying to compile a C++ project using clang and I'm getting some errors.
I've reduced my problem to the following code lines:


template<typename T>
struct Base
{
    void foo(int) {}
};

template<typename T>
struct Derived :  Base<T>
{
    void bar()
    {
        this->foo(2);
    }

    void foobar()
    {
        T c;
        foo(c);
    }
};

int main()
{
    Derived<int> x;
    x.bar();                  //< OK
    x.foobar();             //< ERROR
}


I get the following error:


/home/achauve/dev/c++/test_clang/test_clang.cpp:18:9: error: use of
undeclared identifier 'foo'
        foo(c);
        ^
        this->
/home/achauve/dev/c++/test_clang/test_clang.cpp:26:7: note: in instantiation
of member function
      'Derived<int>::foobar' requested here
    x.foobar();
      ^
/home/achauve/dev/c++/test_clang/test_clang.cpp:4:10: note: must qualify
identifier to find this declaration in
      dependent base class
    void foo(int) {}
         ^


In the case of foobar with a dependant template-parameter, shouldn't the
identifier be found anyway? (gcc doesn't complain).

I've also looked in the directory clang/tests/cxx/temp but I'm not sure
where I could put my test (what's the exact paragraph of the standard
corresponding to this issue?).

I'm using clang-2.8 and also a snapshot from the trunk (clang version 2.9
(trunk 120732)) on Unbuntu 10.10 x86-64.

Thanks,

Cheers,
Adrien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101203/60bb234a/attachment.html>


More information about the cfe-dev mailing list