Deduction guides and variational class templates with variational template constructors - inappropriate argument package lengths

Consider the following class definition and subtraction guide :

 template <typename... Ts> struct foo : Ts... { template <typename... Us> foo(Us&&... us) : Ts{us}... { } }; template <typename... Us> foo(Us&&... us) -> foo<Us...>; 

If I try to create an instance of foo with explicit template arguments, the code compiles correctly:

 foo<bar> a{bar{}}; // ok 

If I try to instantiate foo through the deduction guide ...

 foo b{bar{}}; 
  • g ++ 7 generates a compiler error:

     prog.cc: In instantiation of 'foo<Ts>::foo(Us ...) [with Us = {bar}; Ts = {}]': prog.cc:15:16: required from here prog.cc:5:27: error: mismatched argument pack lengths while expanding 'Ts' foo(Us... us) : Ts{us}... { } ^~~ 
  • clang ++ 5 explodes:

     #0 0x0000000001944af4 PrintStackTraceSignalHandler(void*) (/opt/wandbox/clang-head/bin/clang-5.0+0x1944af4) #1 0x0000000001944dc6 SignalHandler(int) (/opt/wandbox/clang-head/bin/clang-5.0+0x1944dc6) #2 0x00007fafb639a390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x0000000003015b30 clang::Decl::setDeclContext(clang::DeclContext*) (/opt/wandbox/clang-head/bin/clang-5.0+0x3015b30) ... clang-5.0: error: unable to execute command: Segmentation fault 

live example in wandbox

While clang ++ is definitely listening (reported as issue # 32673 ), is g ++ rejecting my code correctly? Is my code badly formed?

+7
c ++ c ++ 17 template-deduction
source share
1 answer

To simplify your example, it seems that GCC does not implement the variational arguments of the pattern in the subtraction guides:

https://wandbox.org/permlink/4YsacnW9wYcoceDH

I did not see any explicit mention of variable patterns in the wording of the subtraction guides in the standard or on cppreference.com. I do not see an interpretation of the standard that prohibits this. So I think this is a mistake.

+7
source share

All Articles