Deduction guides and variadic class templates with variadic template constructors - mismatched argument pack...












7














Consider the following class definition and deduction 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 instantiate 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 produces 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 on wandbox



While clang++ is definitely bugged (reported as issue #32673), is g++ correct in rejecting my code? Is my code ill-formed?










share|improve this question




















  • 3




    Specifically, the problem seems to be that Ts is not correctly deduced
    – Ben Steffan
    Apr 15 '17 at 20:50
















7














Consider the following class definition and deduction 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 instantiate 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 produces 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 on wandbox



While clang++ is definitely bugged (reported as issue #32673), is g++ correct in rejecting my code? Is my code ill-formed?










share|improve this question




















  • 3




    Specifically, the problem seems to be that Ts is not correctly deduced
    – Ben Steffan
    Apr 15 '17 at 20:50














7












7








7







Consider the following class definition and deduction 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 instantiate 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 produces 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 on wandbox



While clang++ is definitely bugged (reported as issue #32673), is g++ correct in rejecting my code? Is my code ill-formed?










share|improve this question















Consider the following class definition and deduction 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 instantiate 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 produces 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 on wandbox



While clang++ is definitely bugged (reported as issue #32673), is g++ correct in rejecting my code? Is my code ill-formed?







c++ c++17 template-deduction






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 15 '17 at 20:41

























asked Apr 15 '17 at 20:24









Vittorio Romeo

57.4k17154293




57.4k17154293








  • 3




    Specifically, the problem seems to be that Ts is not correctly deduced
    – Ben Steffan
    Apr 15 '17 at 20:50














  • 3




    Specifically, the problem seems to be that Ts is not correctly deduced
    – Ben Steffan
    Apr 15 '17 at 20:50








3




3




Specifically, the problem seems to be that Ts is not correctly deduced
– Ben Steffan
Apr 15 '17 at 20:50




Specifically, the problem seems to be that Ts is not correctly deduced
– Ben Steffan
Apr 15 '17 at 20:50












1 Answer
1






active

oldest

votes


















7














To simplify your example further, it appears that GCC does not implement variadic template arguments in deduction guides:



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



I didn't see any explicit mention of variadic templates in the wording for deduction guides in the standard or on cppreference.com. I see no interpretation of the standard that disallows this. Therefore I think this is a bug.






share|improve this answer



















  • 2




    Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
    – chris
    Apr 15 '17 at 20:50










  • Agreed. Reported as bug #80438.
    – Vittorio Romeo
    Apr 15 '17 at 21:06






  • 1




    Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
    – Jackie
    Apr 15 '17 at 21:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43430921%2fdeduction-guides-and-variadic-class-templates-with-variadic-template-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














To simplify your example further, it appears that GCC does not implement variadic template arguments in deduction guides:



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



I didn't see any explicit mention of variadic templates in the wording for deduction guides in the standard or on cppreference.com. I see no interpretation of the standard that disallows this. Therefore I think this is a bug.






share|improve this answer



















  • 2




    Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
    – chris
    Apr 15 '17 at 20:50










  • Agreed. Reported as bug #80438.
    – Vittorio Romeo
    Apr 15 '17 at 21:06






  • 1




    Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
    – Jackie
    Apr 15 '17 at 21:15
















7














To simplify your example further, it appears that GCC does not implement variadic template arguments in deduction guides:



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



I didn't see any explicit mention of variadic templates in the wording for deduction guides in the standard or on cppreference.com. I see no interpretation of the standard that disallows this. Therefore I think this is a bug.






share|improve this answer



















  • 2




    Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
    – chris
    Apr 15 '17 at 20:50










  • Agreed. Reported as bug #80438.
    – Vittorio Romeo
    Apr 15 '17 at 21:06






  • 1




    Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
    – Jackie
    Apr 15 '17 at 21:15














7












7








7






To simplify your example further, it appears that GCC does not implement variadic template arguments in deduction guides:



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



I didn't see any explicit mention of variadic templates in the wording for deduction guides in the standard or on cppreference.com. I see no interpretation of the standard that disallows this. Therefore I think this is a bug.






share|improve this answer














To simplify your example further, it appears that GCC does not implement variadic template arguments in deduction guides:



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



I didn't see any explicit mention of variadic templates in the wording for deduction guides in the standard or on cppreference.com. I see no interpretation of the standard that disallows this. Therefore I think this is a bug.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 16 '17 at 0:26









R Sahu

164k1291184




164k1291184










answered Apr 15 '17 at 20:48









Jackie

461211




461211








  • 2




    Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
    – chris
    Apr 15 '17 at 20:50










  • Agreed. Reported as bug #80438.
    – Vittorio Romeo
    Apr 15 '17 at 21:06






  • 1




    Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
    – Jackie
    Apr 15 '17 at 21:15














  • 2




    Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
    – chris
    Apr 15 '17 at 20:50










  • Agreed. Reported as bug #80438.
    – Vittorio Romeo
    Apr 15 '17 at 21:06






  • 1




    Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
    – Jackie
    Apr 15 '17 at 21:15








2




2




Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
– chris
Apr 15 '17 at 20:50




Considering std::tuple has deduction guides, I'd say it's pretty safe to assume that variadic templates are allowed.
– chris
Apr 15 '17 at 20:50












Agreed. Reported as bug #80438.
– Vittorio Romeo
Apr 15 '17 at 21:06




Agreed. Reported as bug #80438.
– Vittorio Romeo
Apr 15 '17 at 21:06




1




1




Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
– Jackie
Apr 15 '17 at 21:15




Yes, it's true, so I went looking for why this works. tuple uses a variadic deduction guide. However because of the enable_if in the tuple constructor the deduction guide doesn't match
– Jackie
Apr 15 '17 at 21:15


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43430921%2fdeduction-guides-and-variadic-class-templates-with-variadic-template-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents