Deducing class template parameters from variadic value-initialization (clang vs g++)

Viewed 131

Consider the following variadic class template:

template <typename... Ts>
struct foo
{
    template <typename... Us>
    foo(Us...) { }
};

If I try to instantiate foo in the following way, both g++(trunk) and clang++(trunk) are happy:

auto o = foo{};

on godbolt.org


As soon as I switch to value-initialization with parentheses, g++ fails to compile (while clang++ is still happy):

auto o = foo();
error: cannot deduce template arguments for 'foo' from ()
     auto o = foo();
                  ^

on godbolt.org


Is this a g++ bug, or is there a difference in the way class template argument deduction is handled between {} and () initialization?


This also happens with a proper deduction guide: https://godbolt.org/g/qReXpM.

0 Answers
Related