I am designing an API using the LLVM library which will accept an output stream as one of its constructor parameters. The LLVM coding standards dictate the following:
Use raw_ostream
LLVM includes a lightweight, simple, and efficient stream implementation in llvm/Support/raw_ostream.h, which provides all of the common features of std::ostream. All new code should use raw_ostream instead of ostream.
Unlike std::ostream, raw_ostream is not a template and can be forward declared as class raw_ostream. Public headers should generally not include the raw_ostream header, but use forward declarations and constant references to raw_ostream instances.
I must abide by the LLVM coding standards, so I am trying to accept a raw_ostream as a parameter in my constructor. I have tried passing a raw_ostream by reference and by pointer, but I receive the following error message at compile time:
note: candidate constructor not viable: no known conversion from 'llvm::raw_ostream &()' to 'llvm::raw_ostream &'...
What should my constructor look like to accept a parameter of type 'llvm::raw_ostream &()'? I would like to initialize a class member to this output stream.
Here is my current code:
Constructor
MyClass(raw_ostream &OS) : OutputStream(OS) {}
Caller
MyClass x = new MyClass(&outs);
outs
is documented beginning at line 665 of this link
There are tons of examples within the LLVM source where raw_ostream
is a function / method argument. It's almost always (..., raw_ostream &OS, ...)
Here's a representative example from CodeGen/AsmPrinter/AsmPrinter.cpp
:
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {
// ... code
}