C++/ObjC++: switch to gnu++17 as the default standard

Clang's default C++ standard is now `gnu++17` instead of `gnu++14`:
https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-standard/64360

* CUDA/HIP are unchanged: C++14 from D103221.
* Sony PS4/PS5 are unchanged: https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-standard/64360/6
* lit feature `default-std-cxx` is added to keep CLANG_DEFAULT_STD_CXX=xxx tests working.
  Whether the cmake variable should be retained is disccused in D133375.

Depends on D131464

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D131465
This commit is contained in:
Fangrui Song 2022-09-08 08:22:04 +00:00
parent 047c7aa96d
commit 3e99b8d947
6 changed files with 24 additions and 10 deletions

View File

@ -200,6 +200,10 @@ C++ Language Changes in Clang
- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` option
to get the old partial ordering behavior regarding packs.
- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
This means Clang will by default accept code using features from C++17 and
conforming GNU extensions. Projects incompatible with C++17 can add
``-std=gnu++14`` to their build settings to restore the previous behaviour.
C++20 Feature Support
^^^^^^^^^^^^^^^^^^^^^

View File

@ -75,10 +75,9 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,
if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
return CLANG_DEFAULT_STD_CXX;
if (T.isDriverKit())
return LangStandard::lang_gnucxx17;
else
if (T.isPS())
return LangStandard::lang_gnucxx14;
return LangStandard::lang_gnucxx17;
case Language::RenderScript:
return LangStandard::lang_c99;
case Language::HIP:

View File

@ -0,0 +1,14 @@
// UNSUPPORTED: default-std-cxx, ps4, ps5
/// Test default standards when CLANG_DEFAULT_STD_CXX is unspecified.
/// PS4/PS5 default to gnu++14.
// RUN: %clang_cc1 -dM -E %s | FileCheck --check-prefix=CXX17 %s
// RUN: %clang_cc1 -dM -E -x cuda %s | FileCheck --check-prefix=CXX14 %s
// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck --check-prefix=CXX14 %s
// RUN: %clang_cc1 -dM -E -x cuda -std=c++14 %s | FileCheck --check-prefix=CXX14 %s
// RUN: %clang_cc1 -dM -E -x hip -std=c++98 %s | FileCheck --check-prefix=CXX98 %s
// CXX98: #define __cplusplus 199711L
// CXX14: #define __cplusplus 201402L
// CXX17: #define __cplusplus 201703L

View File

@ -1,7 +0,0 @@
// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck -check-prefix=CXX14 %s
// RUN: %clang_cc1 -dM -E %s | FileCheck -check-prefix=CXX14 %s
// RUN: %clang_cc1 -dM -E -std=c++98 -x hip %s | FileCheck -check-prefix=CXX98 %s
// RUN: %clang_cc1 -dM -E -std=c++98 %s | FileCheck -check-prefix=CXX98 %s
// CXX98: #define __cplusplus 199711L
// CXX14: #define __cplusplus 201402L

View File

@ -131,6 +131,9 @@ if config.clang_default_pie_on_linux:
if config.clang_enable_opaque_pointers:
config.available_features.add('enable-opaque-pointers')
if config.clang_default_std_cxx != '':
config.available_features.add('default-std-cxx')
# Set available features we allow tests to conditionalize on.
#
if config.clang_default_cxx_stdlib != '':

View File

@ -24,6 +24,7 @@ config.have_zlib = @LLVM_ENABLE_ZLIB@
config.clang_arcmt = @CLANG_ENABLE_ARCMT@
config.clang_default_pie_on_linux = @CLANG_DEFAULT_PIE_ON_LINUX@
config.clang_enable_opaque_pointers = @CLANG_ENABLE_OPAQUE_POINTERS_INTERNAL@
config.clang_default_std_cxx = "@CLANG_DEFAULT_STD_CXX@"
config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@