Consider the following code:
struct S {
using T = int;
operator T() { return 42; }
};
int main() {
S s;
S::T t = s;
// Is the following line correct?
t = s.operator T();
}
It compiles with GCC (4.9/5.1/6.1), but it fails to compile with clang (3.8/3.7).
The error returned is:
error: unknown type name 'T'; did you mean 'S::T'?
Which compiler is right in this case and why?
Note
Solving it is a matter of qualifying T
:
t = s.operator S::T();
The question is not about how to make it work.
I believe this is clang bug (submitted as #27807)
From [basic.lookup.classref]:
In
t = s.operator T();
,T
is first looked up in the class ofS
, which should find your typedef and hence end up callingoperator int()
.