gcc accepts the following, but clang does not:
template
class Container {
class iterator;
void method(iterator);
void convenienceMethod(iterator n) { method(++n); }
}
Clang says that Container::iterator is an incomplete type. The situation seems similar to this: http://clang.llvm.org/compatibility.html#undep_incomplete
except in this case, the type is nested inside the template, which I had hoped would make the method body be ignored until instantiation (as in gcc).
My understanding is that since Container::iterator is part of the current instantiation, it is not considered a dependent type, so clang is correct by temp.res 8.5.1 and I should not open a bug report.
…but this is nice syntax when implementing containers, so I hope I am wrong.
Thanks,
Ken
gcc accepts the following, but clang does not:
template
class Container {
class iterator;
void method(iterator);
void convenienceMethod(iterator n) { method(++n); }
}
Clang says that Container::iterator is an incomplete type. The situation seems similar to this: http://clang.llvm.org/compatibility.html#undep_incomplete
except in this case, the type is nested inside the template, which I had hoped would make the method body be ignored until instantiation (as in gcc).
My understanding is that since Container::iterator is part of the current instantiation, it is not considered a dependent type, so clang is correct by temp.res 8.5.1 and I should not open a bug report.
…but this is nice syntax when implementing containers, so I hope I am wrong.
I’m afraid you’re not wrong; this is ill-formed (no diagnostic required). You can work around that by making the type “more dependent”. With the recently-approved std::type_identity feature (which is trivial to reimplement for yourself if you don’t want to wait for C++20), you can use std::type_identity_t to achieve this.