Paul C. Anagnostopoulos via llvm-dev
2021-Mar-31 00:02 UTC
[llvm-dev] C++ compiler error I do not understand
I have the following situation with which I could use some enlightenment. As usual, the context is TableGen. in class Record: public: using AssertionTuple = std::tuple<SMLoc, Init *, Init *>; ... SmallVector<AssertionTuple, 0> Assertions; then there exists: struct RecordsEntry { std::unique_ptr<Record> Rec; std::unique_ptr<ForeachLoop> Loop; std::unique_ptr<Record::AssertionTuple> Assertion; void dump() const; RecordsEntry() {} RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec)) {} RecordsEntry(std::unique_ptr<ForeachLoop> Loop) : Loop(std::move(Loop)) {} RecordsEntry(std::unique_ptr<Record::AssertionTuple> Assertion) // 4th constructor : Assertion(std::move(Assertion)) {} }; ... bool TGParser::addEntry(RecordsEntry E) { ... Note that I expect to create a RecordsEntry by passing an AssertionTuple to addEntry and having the 4th constructor do the trick. The other three constructors all work fine. However, when I do this: Record::AssertionTuple tuple = std::make_tuple(ConditionLoc, Condition, Message); addEntry(std::move(tuple)); I get this: C:\LLVM\llvm-project\llvm\lib\TableGen\TGParser.cpp(3190): error C2664: 'bool llvm::TGParser::addEntry(llvm::RecordsEntry)': cannot convert argument 1 from 'llvm::Record::AssertionTuple' to 'llvm::RecordsEntry' C:\LLVM\llvm-project\llvm\lib\TableGen\TGParser.cpp(3190): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:\LLVM\llvm-project\llvm\lib\TableGen\TGParser.cpp(344): note: see declaration of 'llvm::TGParser::addEntry' Ah, I guess I should show the definitions of the three arguments passed to make_tuple() above: SMLoc ConditionLoc = Lex.getLoc(); Init *Condition = ParseValue(CurRec); Init *Message = ParseValue(CurRec); Since there is no complaint about making the tuple, I assume those three arguments have the correct type. The problem is the 4th RecordsEntry constructor, which cannot convert the addEntry argument 'std::move(tuple)' to a Record::AssertionTuple, even though that's exactly what it is. P.S.: Regardless of what I learn here, I'm going to change the assertion tuple into a little struct, which should work fine as demonstrated by constructor 3 above. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210330/4990d064/attachment.html>
Krzysztof Parzyszek via llvm-dev
2021-Mar-31 00:10 UTC
[llvm-dev] C++ compiler error I do not understand
The 4th constructor takes a (unique) pointer, not a reference, but you pass an rvalue reference. If you really need an unique pointer, you can make one with std::make_unique. -- Krzysztof Parzyszek kparzysz at quicinc.com<mailto:kparzysz at quicinc.com> AI tools development From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Paul C. Anagnostopoulos via llvm-dev Sent: Tuesday, March 30, 2021 7:03 PM To: LLVM dev <llvm-dev at lists.llvm.org> Subject: [EXT] [llvm-dev] C++ compiler error I do not understand I have the following situation with which I could use some enlightenment. As usual, the context is TableGen. in class Record: public: using AssertionTuple = std::tuple<SMLoc, Init *, Init *>; ... SmallVector<AssertionTuple, 0> Assertions; then there exists: struct RecordsEntry { std::unique_ptr<Record> Rec; std::unique_ptr<ForeachLoop> Loop; std::unique_ptr<Record::AssertionTuple> Assertion; void dump() const; RecordsEntry() {} RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec)) {} RecordsEntry(std::unique_ptr<ForeachLoop> Loop) : Loop(std::move(Loop)) {} RecordsEntry(std::unique_ptr<Record::AssertionTuple> Assertion) // 4th constructor : Assertion(std::move(Assertion)) {} }; ... bool TGParser::addEntry(RecordsEntry E) { ... Note that I expect to create a RecordsEntry by passing an AssertionTuple to addEntry and having the 4th constructor do the trick. The other three constructors all work fine. However, when I do this: Record::AssertionTuple tuple = std::make_tuple(ConditionLoc, Condition, Message); addEntry(std::move(tuple)); I get this: C:\LLVM\llvm-project\llvm\lib\TableGen\TGParser.cpp(3190): error C2664: 'bool llvm::TGParser::addEntry(llvm::RecordsEntry)': cannot convert argument 1 from 'llvm::Record::AssertionTuple' to 'llvm::RecordsEntry' C:\LLVM\llvm-project\llvm\lib\TableGen\TGParser.cpp(3190): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:\LLVM\llvm-project\llvm\lib\TableGen\TGParser.cpp(344): note: see declaration of 'llvm::TGParser::addEntry' Ah, I guess I should show the definitions of the three arguments passed to make_tuple() above: SMLoc ConditionLoc = Lex.getLoc(); Init *Condition = ParseValue(CurRec); Init *Message = ParseValue(CurRec); Since there is no complaint about making the tuple, I assume those three arguments have the correct type. The problem is the 4th RecordsEntry constructor, which cannot convert the addEntry argument 'std::move(tuple)' to a Record::AssertionTuple, even though that's exactly what it is. P.S.: Regardless of what I learn here, I'm going to change the assertion tuple into a little struct, which should work fine as demonstrated by constructor 3 above. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210331/9b9dfb47/attachment.html>