(очень упрощенный пример)
Код: Выделить всё
class MyError {
public:
enum ErrorType : int {
none,
type1,
type2
};
MyError (ErrorType type, const std::string& description)
{
}
};
template
tl::unexpected (MyError::ErrorType, const T&)->tl::unexpected;
но не может скомпилироваться с Clang 14–18. Кроме того, Clang выдает странные сообщения об ошибках (например, синтаксис полностью нарушен):
Код: Выделить всё
:2476:35: error: expected ')'
2476 | tl::unexpected (MyError::ErrorType, const T&)->tl::unexpected;
| ^
:2476:16: note: to match this '('
2476 | tl::unexpected (MyError::ErrorType, const T&)->tl::unexpected;
| ^
:2476:16: error: cannot use parentheses when declaring variable with deduced class template specialization type
2476 | tl::unexpected (MyError::ErrorType, const T&)->tl::unexpected;
| ^
:2476:26: error: declaration of variable 'ErrorType' with deduced type 'tl::unexpected' requires an initializer
2476 | tl::unexpected (MyError::ErrorType, const T&)->tl::unexpected;
| ^
:2476:46: error: expected ';' at end of declaration
2476 | tl::unexpected (MyError::ErrorType, const T&)->tl::unexpected;
| ^
| ;
:2476:46: error: cannot use arrow operator on a type
5 errors generated.
Compiler returned: 1
Код: Выделить всё
template
tl::unexpected (int, const T&)->tl::unexpected;
Код: Выделить всё
:2476:17: error: expected unqualified-id
2476 | tl::unexpected (int, const T&)->tl::unexpected;
| ^
:2476:17: error: expected ')'
:2476:16: note: to match this '('
2476 | tl::unexpected (int, const T&)->tl::unexpected;
| ^
2 errors generated.
Compiler returned: 1
Код: Выделить всё
template
class C
{
private:
T1 a;
T2 b;
};
template
C (int, const T&)->C;
Вот ссылка проводника компилятора на приведенный выше пример. :
https://godbolt.org/z/z3Ybrx1he
Пример кода находится в конце (строка 2450 и ниже) после содержимого заголовка tl::expected. Похоже, ни clang, ни gcc не знают о std::expected, поэтому я использую tl::expected.
Подробнее здесь: https://stackoverflow.com/questions/789 ... compiles-w