2

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?

Jere
  • 1,196
  • 1
  • 9
  • 31
  • 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? – Some programmer dude Sep 28 '20 at 21:38
  • 1
    Have you tried [setting CCXFLAGS](https://stackoverflow.com/q/21581838/10957435)? –  Sep 28 '20 at 21:39
  • 1
    Also related: https://stackoverflow.com/q/18040048/10957435 –  Sep 28 '20 at 21:40
  • @Someprogrammerdude thanks, but I am looking for a way that doesn't even include a makefile - if that is possible... – Jere Sep 28 '20 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. – Some programmer dude Sep 28 '20 at 21:51
  • so if I don't want to use an alias (which wouldn't really set a *default* because I couldn't set different flags for divergent files/projects, it would just carve one flag in stone), the only way to solve this is a makefile i.e. set a flag every time I compile something? – Jere Sep 28 '20 at 21:57

1 Answers1

2

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

alias g++='g++ -std=c++20'
Rishabh Deep Singh
  • 807
  • 1
  • 12
  • 24
  • 2
    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 – Jere Sep 28 '20 at 22:00