Should a name lookup be deferred for the class / namespace -name assigned by this-> in the class template definition?

clang 3.0 and g ++ 4.8.1 both reject the following code with the error shown in the comment:

template<typename T> struct S { void f() { this->dependent(); // no error: type of 'this' is dependent? this->Dependent::dependent(); // error: 'Dependent' has not been declared } }; 

According to [basic.lookup.classref]

class name or namespace name following. or →, both in the context of the entire postfix expression and in the scope of the object's expression class.

And [temp.dep.expr]

this depends on the type, depends on the class type of the incoming member function.

If the class or name of the Dependent namespace is looked up "in the scope of the * this object’s expression class, and the object’s expression class depends if this search is not delayed until the template is created? Does the standard indicate the correct behavior?

EDIT: clang 3.0 accepts the following code, but g ++ 4.8 gives the same error as above

 template<typename T> struct S { T m; void f() { m.dependent(); m.Dependent::dependent(); } }; 
+4
source share
1 answer

In your first code, both lines are “unformatted, no diagnostics required”, because “this” refers to the current instance, but no element was found, and the class template does not have dependent base classes.

He is not a member of the current instance or unknown specialization. See 14.6.2.1p6

+2
source

Source: https://habr.com/ru/post/1490179/


All Articles