[cfe-dev] Typeid and forward declaration - Clarification needed
Karen Shaeffer
shaeffer at neuralscape.com
Tue Oct 29 14:40:56 PDT 2013
On Tue, Oct 29, 2013 at 02:14:11PM -0700, Richard Smith wrote:
> 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."
>
Hi Richard,
There is no ambiguity there. The standard defines it concisely. I actually thought
whether a compiler rejected that example was implementation specific, depending on
the compiler's template instantiation stategy. But c++11 defines it as an ill-formed
program. Is that test case an ill-formed program in the previous standard?
enjoy,
Karen
--
Karen Shaeffer Be aware: If you see an obstacle in your path,
Neuralscape Services that obstacle is your path. Zen proverb
More information about the cfe-dev
mailing list