[cfe-dev] Clang bug, temp.res p8, or something else?

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 22 19:45:46 PDT 2018


On Fri, 22 Jun 2018, 19:40 Kenneth Camann via cfe-dev, <
cfe-dev at lists.llvm.org> wrote:

> gcc accepts the following, but clang does not:
>
> template <typename T>
> 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<iterator> to achieve this.

Thanks,
> Ken
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180622/31ffdfec/attachment.html>


More information about the cfe-dev mailing list