К моменту проверки ограничений конструктора по умолчанию
не следует вводить d — и, следовательно, также вводить b —
можно считать законченным? GCC принимает создание объекта
типа b, но и Clang, и MSVC его отвергают.
И это не просто создание объекта b > объект, который приводит
к этому результату. Даже простое использование псевдонима вложенного типа b::d (т. е. использование w = b::d;)
приведет к такому же несоответствию.
Как ни странно, эта разница в поведении компилятора, похоже, возникает только
когда пользователь предоставляет конструктор по умолчанию типа a
, ограничивая его с помощью c. Каков ожидаемый результат
этой программы?
template
concept c = requires { sizeof(T); };
template
struct a {
struct d : B {};
a() requires c = default;
};
struct b : a {};
auto v = b{}; // clang nope, gcc ok, msvc nope
Демо
Сообщение об ошибке Clang:
:6:16: error: base class has incomplete type
6 | struct d : B {};
| ^
:2:24: note: in instantiation of member class 'a::d' requested here
2 | concept c = requires { sizeof(T); };
| ^
:2:24: note: in instantiation of requirement here
2 | concept c = requires { sizeof(T); };
| ^~~~~~~~~
:2:13: note: while substituting template arguments into constraint
expression here
2 | concept c = requires { sizeof(T); };
| ^~~~~~~~~~~~~~~~~~~~~~~
:7:18: note: while checking the satisfaction of concept 'c'
requested here
7 | a() requires c = default;
| ^~~~
:7:18: note: while substituting template arguments into constraint
expression here
7 | a() requires c = default;
| ^~~~
:7:5: note: while checking constraint satisfaction for function 'a'
required here
7 | a() requires c = default;
| ^
:9:12: note: in instantiation of template class 'a' requested here
9 | struct b : a {};
| ^
:9:8: note: definition of 'b' is not complete until the closing '}'
9 | struct b : a {};
| ^
:10:12: error: no matching constructor for initialization of 'a'
10 | auto v = b{};
| ^
:7:5: note: candidate constructor not viable: constraints not satisfied
7 | a() requires c = default;
| ^
:7:18: note: because 'd' does not satisfy 'c'
7 | a() requires c = default;
| ^
:2:24: note: because 'sizeof(T)' would be invalid
2 | concept c = requires { sizeof(T); };
| ^
:5:8: note: candidate constructor (the implicit copy constructor)
not viable: requires 1 argument, but 0 were provided
5 | struct a {
| ^
:5:8: note: candidate constructor (the implicit move constructor)
not viable: requires 1 argument, but 0 were provided
5 | struct a {
| ^
Сообщение об ошибке MSVC:
(6): error C2504: 'b': base class undefined
(6): note: the template instantiation context (the oldest one first) is
(7): note: while evaluating concept 'c'
(6): note: while compiling class 'a::d'
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-complete
Когда параметр шаблона неполного типа становится полным? ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение