简体   繁体   中英

Is it legal to expand non-type parameter pack to define internal class template with non-type template parameters?

The minimal code I was able to generate to reproduce the problem:

template <int>
struct Tag { };

Tag<0> w;

template <int... Is>
struct Outer {
   template <Tag<Is> &...>
   struct Inner {
   };
};

int main() {
   Outer<0>::Inner<w> f;
}

g++ (version 6.1.1 20160511) encounters following error while compiling the code:

 pp.cc: In function 'int main()': pp.cc:14:21: internal compiler error: unexpected expression 'Is' of kind template_parm_index Outer<0>::Inner<w> f; 

And produces long and boring stack trace. clang++ in version 3.6.0 does not seem to have any problem with compiling the code. The same code with type template parameters compiles just fine in both compilers:

template <class>
struct Tag { };

Tag<int> w;

template <class... Ts>
struct Outer {
   template <Tag<Ts> &...>
   struct Inner {
   };
};

int main() {
   Outer<int>::Inner<w> f;
}

So is it a g++ bug or am I missing something important about non-type variadic template parameters expansion which does not apply to class template parameters expansion?

(Not an answer but someone might be interested)

Possible relatively simple workaround for GCC:

template <int>
struct Tag { };

Tag<0> w;

template <class... Ts>
struct OuterParent {
   template <Ts&...>
   struct Inner {
   };
};

template <int... Is>
struct Outer:OuterParent<Tag<Is>...> {
};

int main() {
   Outer<0>::Inner<w> f;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM