Setting the CXX_STANDARD does not work

When I try to use set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20) it won’t set the target to 20, or at least, the output doesn’t show it and CLion does not detect that the standard is C++17 and above (Try to do namespace Foo::Bar {...}).

You can try reproducing it with this on Windows 10 with VS 2019.

What’s going on here and how do I fix it?

Actually, it’s not even “hidden” it just isn’t set even:

error C2429: language feature 'nested-namespace-definition' requires compiler flag '/std:c++17'

I had to define:

set_target_properties(${PROJECT_NAME} PROPERTIES
  CXX_STANDARD 20
  CXX_STANDARD_REQUIRED ON
  CXX_EXTENSIONS OFF
)
1 Like

@craig.scott wrote a blog on this for those interested:

1 Like