Код: Выделить всё
#include
struct B;
/// This template is never used in this translation unit, but somehow it's instantiated.
template
struct A
{
void set_b(std::unique_ptr b)
{
_b = std::move(b);
}
std::unique_ptr _b;
};
int main()
{
}
Начиная с clang-17, где была добавлена поддержка флага -std=c++23, и выше эта проблема сохраняется: компилятор принудительно создает экземпляры шаблонов в единицах перевода, которые никогда его не используют и включают только заголовочный файл там, где он определен. И виновником здесь является именно std::unique_ptr.
Код: Выделить всё
In file included from :2:
In file included from /cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_17.0.1/bin/../include/c++/v1/memory:898:
In file included from /cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_17.0.1/bin/../include/c++/v1/__memory/shared_ptr.h:31:
/cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_17.0.1/bin/../include/c++/v1/__memory/unique_ptr.h:66:19: error: invalid application of 'sizeof' to an incomplete type 'B'
66 | static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
| ^~~~~~~~~~~
/cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_17.0.1/bin/../include/c++/v1/__memory/unique_ptr.h:300:7: note: in instantiation of member function 'std::default_delete::operator()' requested here
300 | __ptr_.second()(__tmp);
| ^
/cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_17.0.1/bin/../include/c++/v1/__memory/unique_ptr.h:234:5: note: in instantiation of member function 'std::unique_ptr::reset' requested here
234 | reset(__u.release());
| ^
:12:12: note: in instantiation of member function 'std::unique_ptr::operator=' requested here
12 | _b = std::move(b);
| ^
:4:8: note: forward declaration of 'B'
4 | struct B;
| ^
1 error generated.
Compiler returned: 1
Подробнее здесь: https://stackoverflow.com/questions/798 ... where-uniq
Мобильная версия