[cfe-dev] Is clang name lookup too restrictive for dependent base classes?

Douglas Gregor dgregor at apple.com
Wed Feb 10 15:01:08 PST 2010


On Feb 10, 2010, at 2:51 PM, Enea Zaffanella wrote:

> Hello.
> 
> The following example is a simplified version of code occurring in 
> doxygen-1.6.2 (in the qtools module):
> 
> =======================================
> template <typename T>
> struct List {
>   void append(const T&) { }
> };
> 
> template <typename T>
> struct Stack : public List<T> {
>   void push(const T& d) { append(d); }
> };
> 
> struct Client {
>   Stack<int> stack;
>   void foo() { stack.push(0); }
> };
> =======================================
> 
> 
> While g++ accepts it, clang complains as follows:
> 
> =======================================
> # llvm/Debug/bin/clang++ -fsyntax-only test.cc
> test.cc:8:27: error: use of undeclared identifier 'append'
>   void push(const T& d) { append(d); }
>                           ^
>                           this->
> test.cc:13:22: note: in instantiation of member function
>       'Stack<int>::push' requested here
>   void foo() { stack.push(0); }
>                      ^
> test.cc:3:8: note: must qualify identifier to find this declaration in
>       dependent base class
>   void append(const T&) { }
>        ^
> 3 diagnostics generated.
> =======================================
> 
> Since the call to append(d) is a type-dependent expression,
> I would say that clang name lookup is too restrictive.
> Or is it the case that g++ is too permissive?

g++ is too permissive. This is two-phase name lookup, which Clang is very strict about.

	- Doug



More information about the cfe-dev mailing list