3

I want to regularly compile C++20 code, using clang.

In the clang command guide (https://clang.llvm.org/docs/CommandGuide/clang.html) it says that I can add a flag (in my case: -std=c++2a) every time I want to compile something.

In the clang user manual (https://clang.llvm.org/docs/UsersManual.html#differences-between-various-standard-modes) it states:

If no -std option is specified, clang defaults to gnu17 mode. Many C99 and C11 features are supported in earlier modes as a conforming extension, with a warning.

But is there a way to permanently change the default mode (i.e. c++-version) that clang uses?

6
  • 1
    Usually you can configure your IDE or other build-environment (makefiles, CMakeLists.txt, etc.) to always add flags and options (including but not limited to the -std option) when building. Is this a problem? Commented Sep 28, 2020 at 21:38
  • 1
    Have you tried setting CCXFLAGS? Commented Sep 28, 2020 at 21:39
  • 1
    Also related: stackoverflow.com/q/18040048/10957435 Commented Sep 28, 2020 at 21:40
  • @Someprogrammerdude thanks, but I am looking for a way that doesn't even include a makefile - if that is possible... Commented Sep 28, 2020 at 21:49
  • While it can be done through the use of aliases, it relies on the complete environment knowing about this alias. It also requires that all systems your project will be built on also need to rely on such an alias. In the long run, setting flags in makefiles or IDE project settings is a better (and definitely more portable) solution. Commented Sep 28, 2020 at 21:51

1 Answer 1

2

you can use an alias to do that although I won't recommend that.

alias g++='g++ -std=c++20'
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, but to me, a default-setting would include the possibility of variations. I don't necessarily want to always compile in c++20 - I just want it to be the default in case I have set no flag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.