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?

7
  • Could you remove the template<class ... T> A(T... any)->A<decltype(any)...>; 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. Commented Nov 18, 2018 at 2:17
  • @johnathan Removing the deduction guide would result in always deducing A<> and the constructor failing. Commented Nov 18, 2018 at 2: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. Commented Nov 18, 2018 at 2: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. Commented Nov 18, 2018 at 2: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. Commented Nov 18, 2018 at 2:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.