Does CLANG_CXX_LANGUAGE_STANDARD affect my Swift app and why is it not set to Compiler Default?

I was just comparing the build settings of two of my apps to try to understand why they behave differently (one of them uses the full screen on iPad, and the other one has small top and bottom black borders, although that's not the issue I want to discuss now). I saw that the option CLANG_CXX_LANGUAGE_STANDARD is set to gnu++0x for the older project, while it's set to gnu++17 for the newer one. The documentation lists different possible values and also a default one:

Compiler Default: Tells the compiler to use its default C++ language dialect. This is normally the best choice unless you have specific needs. (Currently equivalent to GNU++98.)

If it really is the best choice (normally), why is it not used when creating a new default Xcode project? Or is it better to select a newer compiler version (GNU++98 sounds quite old compared to GNU++17)? Also, does this affect Swift code?

Answered by endecotp in 825150022

If you don’t have C++ code in your project, none of this matters.

For a new project, I suggest choosing C++23. Choose the GNU option only if you know you’ll be using GNU extensions. Choose an older version only if you know you have code written to an older spec and you know it had problems with newer language variants.

Note this isn’t choosing a newer or older version of the compiler - rather, it’s telling the current compiler to support a different variant of the language. It turns features on and off.

I think the default is an old version in order that old code doesn’t suddenly stop compiling when you update Xcode. I disagree with the suggestion that this is the best choice for a new project. Set it to the current version when you start a new project; when you get a new compiler that supports a newer version, consider whether to increase it or not.

Accepted Answer

If you don’t have C++ code in your project, none of this matters.

For a new project, I suggest choosing C++23. Choose the GNU option only if you know you’ll be using GNU extensions. Choose an older version only if you know you have code written to an older spec and you know it had problems with newer language variants.

Note this isn’t choosing a newer or older version of the compiler - rather, it’s telling the current compiler to support a different variant of the language. It turns features on and off.

I think the default is an old version in order that old code doesn’t suddenly stop compiling when you update Xcode. I disagree with the suggestion that this is the best choice for a new project. Set it to the current version when you start a new project; when you get a new compiler that supports a newer version, consider whether to increase it or not.

Thank you for your insight!

Does CLANG_CXX_LANGUAGE_STANDARD affect my Swift app and why is it not set to Compiler Default?
 
 
Q