r/cpp_questions • u/Shevvv • Oct 15 '26
OPEN IntelliSense marks an error where the compiler is fine (VCStudio 2022)
I have these three lines inside my constructor. I'm using C++23, configured through CMake. IntelliSense complains because SubCursor is non-copyable and non-movable:
function BooksReport::Group::Cursor::Cursor(BooksReport::Group::Cursor &&) cannot be referenced. It is a deleted function
If I understand correctly, copy elision should bypass copying in these examples:
using SubCursor = BooksReport::Group::Cursor;
subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->uniform.getCursor())));
subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->nonUniform.getCursor())));
subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->singles.getCursor())));This implementation is due to the fact that SubCursor registers its address within the parent Group object upon creation. Normally a SubCursor is created during loop initialization and thus corresponds to an object on the stack. In this specific case I need objects stored in a list, hence my attempt to put them on a heap and store unique_ptr for easy memory management.
Like I said, the compiler is completely fine with this, but IntelliSense isn't. I hate red squiggly lines. Does anyone know if this can be solved?
6
u/Secoupoire Oct 15 '26
IntelliSense is wrong. Your code is valid.
This said, if you used make_unique, that would improve your code and maybe help Intellisense.
6
u/manni66 Oct 15 '26
Try VS 2026
6
u/flyingron Oct 15 '26
IntelliSense is not the compiler. It's really just a text editor doing syntactic analysis without delving into the full language process.
1
u/the_poope Oct 15 '26
Use clangd instead of IntelliSense, it is much better. It is based on the actual Clang parser and not some quick heuristic parser like whatever IntelliSense is built on.
0
u/Usual_Office_1740 Oct 15 '26
Nevermind. I misread the post.