[cfe-dev] Typeid and forward declaration - Clarification needed
Richard Smith
richard at metafoo.co.uk
Tue Oct 29 14:14:11 PDT 2013
On Tue, Oct 29, 2013 at 1:29 AM, Rahul Jain <1989.rahuljain at gmail.com>wrote:
>
> Hi all,
>
> This is with respect to the following TC.
>
> struct S;
>
> template <typename T>
> static bool fn (S *s)
> {
> return typeid (*s) == typeid (T);
> }
>
> struct S
> {
> };
>
> bool x = fn<S> (__null);
>
>
> The standard says:
> If the type of the type-id is a class type or a reference to a class type,
> the class shall be completely-defined.
>
>
> This "shall" is kind of confusing. Is this a valid TC. Is forward
> declaration allowed while using the typeid operator?
>
No, but the rules are slightly different because this occurs inside a
template. This testcase is ill-formed, but no diagnostic is required, per
[temp.res](14.6)p8:
"If a type used in a non-dependent name is incomplete at the point at which
a template is defined but is complete at the point at which an
instantiation is done, and if the completeness of that type affects whether
or not the program is well-formed or affects the semantics of the program,
the program is ill-formed; no diagnostic is required."
So the template has no valid specializations. Further, we're allowed to
reject this even if the template is never instantiated:
"If no valid specialization can be generated for a template, and that
template is not instantiated, the template is ill-formed, no diagnostic
required."
> Any clarification on the same would be appreciated.
>
> Thanks,
> Rahul
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131029/009918d0/attachment.html>
More information about the cfe-dev
mailing list