When repeating the declaration of a template class with defaulted argument, I get an error:
<source>:12:23: error: redefinition of default argument for 'class<template-parameter-1-2>'
12 | template <typename T, typename = T>
| ^~~~~~~~
<source>:9:23: note: original definition appeared here
9 | template <typename T, typename = T>
|
Repeating a template forward declaration without default arguments doesn't give any errors. Repeating the same one, but without defaulting the argument also works (but IMO it doesn't make sense and should give some error).
Here's the whole example:
template <typename T>
struct ok;
template <typename T>
struct ok;
template <typename T, typename = T>
struct not_ok;
template <typename T, typename = T>
struct not_ok;
template <typename T, typename = T>
struct why_is_it_ok;
template <typename T, typename>
struct why_is_it_ok;
WHY?
Just like default parameters for function parameters, default parameters for template parameters are only allowed to be set once per scope.
template <typename T>
struct ok;
template <typename T>
struct ok;
Is fine because niether declaration introduces a default parameter.
template <typename T, typename = T>
struct not_ok;
template <typename T, typename = T>
struct not_ok;
Is not allowed because the second unnamed parameter is defaulted twice in the same scope.
template <typename T, typename = T>
struct why_is_it_ok;
template <typename T, typename>
struct why_is_it_ok;
Is allowed because only the first declaration declares a default parameter