[cfe-dev] dependent name related question

guoqing zhang gqzhang81 at gmail.com
Fri Mar 6 00:55:03 PST 2015


Hi Richard,

So X is a dependent type  ? which of the following categories X belongs to ?


   - template parameter
   - a member of an *unknown specialization* (see below)
   - a nested class/enum that is a dependent member of *unknown
   specialization* (see below)
   - a cv-qualified version of a dependent type
   - a compound type constructed from a dependent type
   - an array type constructed from a dependent type, or whose size is a
   value-dependent constant expression (see below)
   - a template-id where either the template name is a template parameter,
   or any of template arguments is type- or value-dependent
   - the result of decltype
   <http://en.cppreference.com/w/cpp/language/decltype> applied to a
   type-dependent expression

(copied from cppreference.com)

Regards
-guoqing


On Thu, Mar 5, 2015 at 12:12 AM, Richard Smith <richard at metafoo.co.uk>
wrote:

> 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/20150306/f5142ba9/attachment.html>


More information about the cfe-dev mailing list