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

Eli Friedman eli.friedman at gmail.com
Fri Dec 3 12:59:51 PST 2010


On Fri, Dec 3, 2010 at 12:52 PM, Adrien Chauve <adrien.chauve at gmail.com> wrote:
> 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).

See http://clang.llvm.org/compatibility.html#dep_lookup_bases .  If
you have any questions after reading that, feel free to ask.

-Eli




More information about the cfe-dev mailing list