簡體   English   中英

編譯錯誤:調用基本類型構造函數時轉換無效

[英]Compilation error: invalid conversion when calling base-type constructor

我正在嘗試在不太大的程序MinGW-64 lljvm下進行編譯。 但是我陷入了使我發瘋的錯誤。

代碼如下:

backend.h

class JVMWritter {
...
static char id;
...
};

backend.cpp

char JVMWriter::id = 0;

JVMWriter::JVMWriter(): FunctionPass(&id) {}

現在,在Pass.h中像下面這樣聲明FunctionPass:

Pass.h

class FunctionPass {
...
explicit FunctionPass (char &pid) : <initialization here> {}
...
};

當我嘗試編譯它時,我不斷收到以下錯誤:

backend.cpp:39:16: error: invalid conversion from 'char*' to 'char' [-fpermissive]
   FunctionPass(&JVMWriter::id), targetData(td), out(o), classname(cls), debug(dbg) {
                ^~~~~~~~~~

In file included from D:/dev/msys64/mingw64/include/llvm/IR/DataLayout.h:27:0,
                 from D:/dev/msys64/mingw64/include/llvm/IR/Module.h:20,
                 from D:/dev/msys64/mingw64/include/llvm/IR/PassManager.h:46,
                 from D:/dev/msys64/mingw64/include/llvm/Analysis/LoopInfo.h:47,
                 from backend.h:29,
                 from backend.cpp:23:
D:/dev/msys64/mingw64/include/llvm/Pass.h:300:12: note:   initializing argument 1 of 'llvm::FunctionPass::FunctionPass(char&)'
   explicit FunctionPass(char &pid) : Pass(PT_Function, pid) {}
            ^~~~~~~~~~~~

backend.cpp:39:16: error: cannot bind rvalue '(char)(& JVMWriter::id)' to 'char&'
   FunctionPass(&JVMWriter::id), targetData(td), out(o), classname(cls), debug(dbg) {
                ^~~~~~~~~~

In file included from D:/dev/msys64/mingw64/include/llvm/Pass.h:388:0,
                 from D:/dev/msys64/mingw64/include/llvm/IR/DataLayout.h:27,
                 from D:/dev/msys64/mingw64/include/llvm/IR/Module.h:20,
                 from D:/dev/msys64/mingw64/include/llvm/IR/PassManager.h:46,
                 from D:/dev/msys64/mingw64/include/llvm/Analysis/LoopInfo.h:47,
                 from backend.h:29,
                 from backend.cpp:23:
D:/dev/msys64/mingw64/include/llvm/PassAnalysisSupport.h: In instantiation of 'llvm::AnalysisUsage& llvm::AnalysisUsage::addRequired() [with PassClass = llvm::LoopInfo]':

backend.cpp:52:27:   required from here
D:/dev/msys64/mingw64/include/llvm/PassAnalysisSupport.h:61:39: error: 'ID' is not a member of 'llvm::LoopInfo'
     return addRequiredID(PassClass::ID);

我的明顯問題:為什么它抱怨我正在嘗試進行無效轉換? 我認為這些片段中沒有這樣的嘗試。

FunctionPass(&id)替換為FunctionPass(id)

當您傳遞&id它是char的指針)時, char char & pid聲明pid作為對char的引用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM