Skip to content

Commit e321c8d

Browse files
committed
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-dialect/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-dialect/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 Close llvm#56946 Reviewed By: #clang-language-wg, aaron.ballman Differential Revision: https://reviews.llvm.org/D131465
1 parent 178554f commit e321c8d

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ C++ Language Changes in Clang
200200

201201
- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` option
202202
to get the old partial ordering behavior regarding packs.
203+
- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
204+
This means Clang will by default accept code using features from C++17 and
205+
conforming GNU extensions. Projects incompatible with C++17 can add
206+
``-std=gnu++14`` to their build settings to restore the previous behaviour.
203207

204208
C++20 Feature Support
205209
^^^^^^^^^^^^^^^^^^^^^

clang/lib/Basic/LangStandards.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,
7575
if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
7676
return CLANG_DEFAULT_STD_CXX;
7777

78-
if (T.isDriverKit())
79-
return LangStandard::lang_gnucxx17;
80-
else
78+
if (T.isPS())
8179
return LangStandard::lang_gnucxx14;
80+
return LangStandard::lang_gnucxx17;
8281
case Language::RenderScript:
8382
return LangStandard::lang_c99;
8483
case Language::HIP:

clang/test/Preprocessor/lang-std.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// UNSUPPORTED: default-std-cxx, ps4, ps5
2+
/// Test default standards when CLANG_DEFAULT_STD_CXX is unspecified.
3+
/// PS4/PS5 default to gnu++14.
4+
5+
// RUN: %clang_cc1 -dM -E %s | FileCheck --check-prefix=CXX17 %s
6+
// RUN: %clang_cc1 -dM -E -x cuda %s | FileCheck --check-prefix=CXX14 %s
7+
// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck --check-prefix=CXX14 %s
8+
9+
// RUN: %clang_cc1 -dM -E -x cuda -std=c++14 %s | FileCheck --check-prefix=CXX14 %s
10+
// RUN: %clang_cc1 -dM -E -x hip -std=c++98 %s | FileCheck --check-prefix=CXX98 %s
11+
12+
// CXX98: #define __cplusplus 199711L
13+
// CXX14: #define __cplusplus 201402L
14+
// CXX17: #define __cplusplus 201703L

clang/test/Preprocessor/lang-std.cu

Lines changed: 0 additions & 7 deletions
This file was deleted.

clang/test/lit.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ def have_host_jit_feature_support(feature_name):
131131
if config.clang_enable_opaque_pointers:
132132
config.available_features.add('enable-opaque-pointers')
133133

134+
if config.clang_default_std_cxx != '':
135+
config.available_features.add('default-std-cxx')
136+
134137
# Set available features we allow tests to conditionalize on.
135138
#
136139
if config.clang_default_cxx_stdlib != '':

clang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ config.have_zlib = @LLVM_ENABLE_ZLIB@
2424
config.clang_arcmt = @CLANG_ENABLE_ARCMT@
2525
config.clang_default_pie_on_linux = @CLANG_DEFAULT_PIE_ON_LINUX@
2626
config.clang_enable_opaque_pointers = @CLANG_ENABLE_OPAQUE_POINTERS_INTERNAL@
27+
config.clang_default_std_cxx = "@CLANG_DEFAULT_STD_CXX@"
2728
config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
2829
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
2930
config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@

0 commit comments

Comments
 (0)