[libcxx-commits] [libcxx] [libc++] Document that backported language features should be used (PR #176993)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 27 05:03:59 PST 2026
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/176993
>From 3deb570bc811bb27b808830777a373d994012f6d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 20 Jan 2026 19:35:57 +0100
Subject: [PATCH] [libc++] Document that backported language features should be
used
---
libcxx/docs/CodingGuidelines.rst | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/libcxx/docs/CodingGuidelines.rst b/libcxx/docs/CodingGuidelines.rst
index 97e6feef9d79b..cb2361c2fc0f2 100644
--- a/libcxx/docs/CodingGuidelines.rst
+++ b/libcxx/docs/CodingGuidelines.rst
@@ -104,12 +104,22 @@ provide alternative spellings for their attributes, so these should be avoided i
This is enforced by the clang-tidy check ``libcpp-uglify-attributes``.
-Use C++11 extensions in C++03 code if they simplify the code
-============================================================
-
-libc++ supports the C++98/03 mode only with the Clang compiler. Clang provides many C++11 features
-in C++03, making it possible to write a lot of code in a simpler way than if we were restricted to C++03 features.
-Some use of extensions is even mandatory, since libc++ supports move semantics in C++03.
+Use extensions if they simplify the code
+========================================
+
+libc++ only supports recent versions Clang and GCC, which allows us to make use of extensions in the code base if both
+compilers support them. Only features backported from future language versions should be used liberally throughout the
+library. For example, some of the most useful extensions are lambdas and ``if constexpr``, since they almost always
+significantly improve readability when used as intended.
+
+libc++ supports the C++98/03 mode only with the Clang compiler. Clang provides many C++11 features in C++03, making it
+possible to write a lot of code in a simpler way than if we were restricted to C++03 features. Some use of extensions is
+even mandatory, since libc++ supports move semantics in C++03. Details on which features have been backported can be
+found
+`here <https://clang.llvm.org/docs/LanguageExtensions.html#language-extensions-back-ported-to-previous-standards>`__.
+
+GCC is only supported from C++11 onwards. Unfortunately, GCC doesn't document which features are backported to older
+language versions, so you just have to try whether GCC accepts the features you want to use.
Use ``using`` aliases instead of ``typedef``
============================================
More information about the libcxx-commits
mailing list