【发布时间】:2017-09-03 11:00:01
【问题描述】:
我正在尝试在 Application 类中创建一个 LLVMContext 成员变量。 MCVE:
#include <llvm/IR/LLVMContext.h>
struct Foo {};
class Application {
public:
Application(int a, Foo foo, int b);
private:
llvm::LLVMContext context_;
};
void function() {
auto application = Application(12, Foo(), 21);
}
但是,添加变量会产生一些非常奇怪的错误:(Clang 4.0.1 和 Apple LLVM 版本 8.1.0)
toy.cpp:13:8: error: no matching constructor for initialization of 'Application' auto application = Application(12, Foo(), 21); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ toy.cpp:5:7: note: candidate constructor (the implicit copy constructor) not viable: expects an l-value for 1st argument class Application { ^ toy.cpp:7:3: note: candidate constructor not viable: requires 3 arguments, but 1 was provided Application(int a, Foo foo, int b); ^ 1 error generated.
这里发生了什么?为什么 Clang 认为我正在尝试使用带有一个参数的构造函数(“但提供了 1”)?
【问题讨论】: