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

Adrien Chauve adrien.chauve at gmail.com
Sat Dec 4 02:12:39 PST 2010


Thanks for the link, it's exactly what I was searching for.

But I'm not sure my example code (ant the example on the page you pointed
at) is invalid. In case of a function call where at least one argument is a
template dependant name, the call should not be qualified (cf "C++ Templates
The Complete Guide" by D. Vandervoorde and N. M. Josuttis, section 9.4.2 pp
136-138).

What am I missing?

Cheers,
Adrien


On Fri, Dec 3, 2010 at 21:59, Eli Friedman <eli.friedman at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101204/2412f82b/attachment.html>


More information about the cfe-dev mailing list