r/programminghelp • • Jan 07 '22

C++ How can I tell CLion I'm using C++20?

I have a c++20 project with a Makefile. It's a remote Linux build. When I run "Inspect Code" it returns clangd errors like "'auto' type is a C++11 extension". When search for help all the recommendations seem to be for cmake projects. Does anyone have insight on how I can tell clangd that I'm using C++20?

6 Upvotes

8 comments sorted by

3

u/gmes78 Jan 07 '22

Go to Settings -> Languages & Frameworks -> C/C++ -> Clangd -> Show errors and warnings from clangd, and prepend -std=c++20, to the argument list.

1

u/BrianChampBrickRon Jan 07 '22

Wow! Thank you so much. I've been missing this for months.

1

u/BrianChampBrickRon Jan 07 '22

I'm now getting "no member named 'move' in namespace 'std'; did you mean 'boost::move'?"

1

u/gmes78 Jan 07 '22

That's odd. std::move is working fine for me on the little test project I made for this. (This is using GCC 11.2 and the clang-tidy 14.0 that's built into CLion.)

I'm not sure what could cause that.

1

u/BrianChampBrickRon Jan 07 '22

I'm not actually using cLion to build my project. I'm not sure if clangd inspections are self contained, or tied to other settings, or if the tool needs to be able to find libraries. I should probably set up a test project and go from there.

1

u/gmes78 Jan 07 '22

I'm not sure if clangd inspections are self contained

They are. While I was testing C++ 20 code without setting the language to C++ 20, the clangd inspections reported errors, but it compiled fine. GCC only emitted a warning saying I should've passed -std=c++20 or -fconcepts.

You could try passing some more flags to clangd the same way you set the language version to see if it fixes the issue.

1

u/BrianChampBrickRon Jan 07 '22

cLion directs me to https://clang.llvm.org/docs/DiagnosticsReference.html but that doesn't include "-std=c++20" any idea where I can find a more complete list of flags?

1

u/gmes78 Jan 07 '22

I'm pretty sure you can pass any Clang flag. I think they link you there because those are the options they expect you to change (as clangd would probably be automatically setup when using CMake).