michaelb / sniprun

A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
MIT License
1.43k stars 46 forks source link

Cpp Compile-Time Error #268

Closed mrPuckk closed 7 months ago

mrPuckk commented 8 months ago

Hi there, I got an issue when using std::vector in Cpp with Sniprun. (g++ compiler)

Describe the bug I am encountering a compile-time error when using vectors declared in C++. The compiler I am using is g++ that set in Sniprun setup.

To Reproduce I'm experiencing a compile-time error only when using Sniprun with code snippets that involve vectors having predefined elements. However, if the vector is declared in the same format without initializing its elements, the code runs smoothly. std::vector<int> myVector{ 5, 10, 15 }; //Got Compile-time Error std::vector<int> A; //Run smoothly Or even I tried a case: std::vector<int> A(5, 10);, it still runs smoothly.

Screenshots

Screenshot 2023-12-28 at 9 45 13 am

Environment:

michaelb commented 8 months ago

Hi, I configured my sniprun instance to run g++ but haven't encountered the issue you mention...

std::vector<int> v {8,4,5,9}; don't fail with 'Compile-time error', and neither do variants (with v = {...}, v; with/without spaces).

Does your code snippet compiles fine outside of sniprun ? I have a fairly recent g++ version, so it may be due to that ..? In any case, you can check sniprun's log at $XDG_CACHE/sniprun/sniprun.log (often ~/Library/Caches on MacOS I believe), with that huge pile of crap text, you should be able to confirm whether you're using g++ as you think you are, and run g++ directly on the generated file ($XDG_CACHE/sniprun/c_original/main.cpp) to see what's the error

michaelb commented 7 months ago

Closing, assuming your problem doesn't bother you anymore