admin管理员组

文章数量:1535345

解决方式

报错相关类,或者使用相关类作为类成员函数的类析构函数需要使用 default 关键字。

问题说明

在编译代码时,遇到了 error: invalid application of ‘sizeof’ to incomplete type “mlir::Pass” 的问题,因为相关代码与 std::unique_ptr 相关,遇到这一问题主要是 mlir::Pass 报错的这个类:

std::unique_ptr<mlir::Pass> xxxxx;

官方关于 std::unique_ptr 有相关说明:

std::unique_ptr may be constructed for an incomplete type T, such as to facilitate the use as a handle in the Pimpl idiom. If the default deleter is used, T must be complete at the point in code where the deleter is invoked, which happens in the destructor, move assignment operator, and reset member function of std::unique_ptr. (Conversely, std::shared_ptr can’t be constructed from a raw pointer to incomplete type, but can be destroyed where T is incomplete).

所以如果是直接创建的 mlir::Pass 对象,并且这个类的完整定义在其他的头文件,那么解决方法就是找到我们需要调用的类的完整定义的头文件,并包含进来即可。

如果是自己写的代码,并且作为类的成员则需要对定义类的析构函数设置为 default:

Demo::~Demo() = default;

主要参考:https://stackoverflow/questions/34072862/why-is-error-invalid-application-of-sizeof-to-an-incomplete-type-using-uniqu

http://blog.linluxiang.info/2015/03/13/pimpl_research/

上面包含头文件的方式,其实相关类的完整定义里面也能看到 virtual ~Pass() = default; 的定义。

本文标签: applicationInvalidErrorsizeofXXXXX