Clang does not notice default template parameters
Considering the following:
[temp.param]/12 - The set of default template-arguments available for use is obtained by merging the default arguments from all prior declarations of the template in the same way default function arguments are [ Example:
template<class T1, class T2 = int> class A; template<class T1 = int, class T2> class A;
is equivalent to
template<class T1 = int, class T2 = int> class A;
— end example ]
The default arguments available for
template <class T>
class Example;
template <class T = void>
class Example {};
will be the defaults arguments in the definition of Example
. The two declarations above will be equivalent to have a single declaration as
template <class T = void>
class Example {};
which will effectively allow doing Example e
.
The original code should be accepted. As a workaround and already suggested in max66's answer, you can provide a deduction guide that uses the default argument
Example() -> Example<>;
I don't know who's right but...
How can I circumvent this issue (apart from partial solutions I described above)?
What about adding the following deduction rule?
Example() -> Example<>;
The following code compile (C++17, obviously) with both g++ and clang++
template <class T>
class Example;
template <class T = void>
class Example {};
Example() -> Example<>;
int main() {
Example e;
}