[cfe-dev] dependent name related question

Richard Smith richard at metafoo.co.uk
Wed Mar 4 14:12:13 PST 2015


On Wed, Mar 4, 2015 at 12:26 PM, guoqing zhang <gqzhang81 at gmail.com> wrote:

> Hi ,
>
> Can somebody explain why I need "typename" before Y<alignof(X)>::type  in
> the following piece of code ?
>
> template<int N> struct Y { typedef int type; };
>
> template<int N> void h() {
>       struct  X {};
>       typename Y<alignof(X)>::type z;
> }
>
> Y<alignof(X)>::type is non-dependent, isn't it ?
>

X is a dependent type [*], so alignof(X) is value-dependent [**], so
Y<alignof(X)> is a dependent type, so you need typename.

[*] This is currently under discussion in CWG; the outcome seems likely to
be that X is treated as a member of the current instantiation.
[**] Even if X is a member of the current instantiation, sizeof(X) and
alignof(X) should be value-dependent; the current standard wording gets
this case wrong.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150304/4f30ed0f/attachment.html>


More information about the cfe-dev mailing list