1

The following fails to compile with gcc 8.2 -std=c++17, with or without deduction guide, but compiles with clang (even clang 5) and latest msvc as you can see here.

template <class... Ts>
struct A
{
    template <class... T>
    A(T... any)
        : tuple_{std::tuple{any...}}
    {

    }

    std::tuple<Ts...> tuple_;
};

template<class ... T>
A(T... any)->A<decltype(any)...>;

int main()
{
    auto f = [](int){};
    auto a1 = A{7};
    auto a2 = A{f,7};
}

As far as I can tell I am not doing anything too strange here, and I thought it would be a typical use case for CTAD.

The question is, which compiler is right?

0.1xer
  • 33
  • 1
  • 6
  • Could you remove the template A(T... any)->A; and see if you can compile successfully? I have GCC 8.2 but unfortunately my standard library is an older version from clang and c++17 does not support dynamic exceptions so... I can use c++17 language features but I have 0 library support. – johnathan Nov 18 '18 at 02:17
  • @johnathan Removing the deduction guide would result in always deducing `A<>` and the constructor failing. –  Nov 18 '18 at 02:28
  • If the question is only about how to have the desired result, rather than which compiler is right, then note that you can make the constructor `A(Ts... ts) : tuple_(ts...) { }` and the user-defined deduction guide will not even be needed. –  Nov 18 '18 at 02:38
  • @eukaryota my library doesn't let me use c++17. The latest standard I can compile with is c++14. Believe me I've mailed my vendor about the issue and was simply told that I should consider c++17 not supported. I hope the gentleman figures out how to fix it soon enough. – johnathan Nov 18 '18 at 02:38
  • @johnathan The question is explicitly about class template argument deduction, which is a new language feature in C++17. It doesn't make sense to answer this for C++14. –  Nov 18 '18 at 02:41
  • @eukaryota godbolt has c++17 though. I'm not answering this in c++14 terms. Thanks for the advice though. – johnathan Nov 18 '18 at 02:42
  • @eukaryota The question is which compiler is right (edited question to clarify). As an example of an actual use case, you could apply type list manipulations and filtering via the deduction guide. – 0.1xer Nov 18 '18 at 07:03

0 Answers0