Skip to content

Conversation

EricWF
Copy link
Member

@EricWF EricWF commented Dec 21, 2023

This change enables that by disabling the C++17 extensions warning
in the test suite and by adding documentation and testing for the use of
this extension.

This change enables that by disabling the C++17 extensions warning
in the test suite and by adding documentation and testing for the use of
this extension.
@EricWF EricWF requested a review from a team as a code owner December 21, 2023 20:06
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 21, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 21, 2023

@llvm/pr-subscribers-libcxx

Author: Eric (EricWF)

Changes

This change enables that by disabling the C++17 extensions warning
in the test suite and by adding documentation and testing for the use of
this extension.


Full diff: https://github.com/llvm/llvm-project/pull/76178.diff

4 Files Affected:

  • (renamed) libcxx/docs/DesignDocs/ExtendedCXXSupport.rst (+18-6)
  • (modified) libcxx/docs/index.rst (+1-1)
  • (added) libcxx/test/libcxx/extensions/test-cxx17-extensions.pass.cpp (+31)
  • (modified) libcxx/utils/libcxx/test/params.py (+2)
diff --git a/libcxx/docs/DesignDocs/ExtendedCXX03Support.rst b/libcxx/docs/DesignDocs/ExtendedCXXSupport.rst
similarity index 82%
rename from libcxx/docs/DesignDocs/ExtendedCXX03Support.rst
rename to libcxx/docs/DesignDocs/ExtendedCXXSupport.rst
index 8c18e563e81997..27d73a3c7a1b23 100644
--- a/libcxx/docs/DesignDocs/ExtendedCXX03Support.rst
+++ b/libcxx/docs/DesignDocs/ExtendedCXXSupport.rst
@@ -1,6 +1,6 @@
-=======================
-Extended C++03 Support
-=======================
+===================================
+Language and Library C++ Extensions
+===================================
 
 .. contents::
    :local:
@@ -10,11 +10,14 @@ Overview
 
 libc++ is an implementation of the C++ standard library targeting C++11 or later.
 
-In C++03, the library implements the C++11 standard using C++11 language extensions provided
+In C++03, the library provides the C++11 standard using C++11 language extensions provided
 by Clang.
 
-This document tracks the C++11 extensions libc++ requires, the C++11 extensions it provides,
-and how to write minimal C++11 inside libc++.
+In other dialects, the library may depend on language extensions provided by the compiler.
+
+This document tracks the C++ extensions libc++ requires from the compiler, and in what dialect.
+Additionally this documents the C++11 extensions libc++ provides, and how to write
+minimal C++11 inside libc++.
 
 Required C++11 Compiler Extensions
 ==================================
@@ -36,6 +39,15 @@ mode. These include:
 *  Trailing return types.
 * ``>>`` without a space.
 
+Required C++17 Compiler Extensions
+==================================
+
+Clang and GCC provide some language extensions in C++11 and later.
+The features libc++ expects Clang & GCC to provide are:
+
+* `if constexpr`
+
+This extension is not available in C++03.
 
 Provided C++11 Library Extensions
 =================================
diff --git a/libcxx/docs/index.rst b/libcxx/docs/index.rst
index c7769bae6bb17d..f4a472b9e622d1 100644
--- a/libcxx/docs/index.rst
+++ b/libcxx/docs/index.rst
@@ -186,7 +186,7 @@ Design Documents
    DesignDocs/AtomicDesign
    DesignDocs/CapturingConfigInfo
    DesignDocs/ExperimentalFeatures
-   DesignDocs/ExtendedCXX03Support
+   DesignDocs/ExtendedCXXSupport
    DesignDocs/FeatureTestMacros
    DesignDocs/FileTimeType
    DesignDocs/HeaderRemovalPolicy
diff --git a/libcxx/test/libcxx/extensions/test-cxx17-extensions.pass.cpp b/libcxx/test/libcxx/extensions/test-cxx17-extensions.pass.cpp
new file mode 100644
index 00000000000000..e38b1f32c2df43
--- /dev/null
+++ b/libcxx/test/libcxx/extensions/test-cxx17-extensions.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// Test that `if constexpr` is provided as an extension by supported compilers
+// in all language dialects after C++03. Also further test that the test suite
+// has disabled -Wc++17-extension because we also disable system headers.
+
+#include <cassert>
+
+// if constexpr doesn't need to be used in a constexpr function, nor a dependent
+// one.
+bool CheckIfConstexpr() {
+  if constexpr (false) {
+    return false;
+  }
+  if constexpr (true) {
+    return true;
+  }
+}
+
+int main(int, char**) {
+  assert(CheckIfConstexpr());
+  return 0;
+}
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 4e209901f43be8..8b4aff2bbdd656 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -57,6 +57,8 @@
     # Disable warnings for extensions used in C++03
     "-Wno-local-type-template-args",
     "-Wno-c++11-extensions",
+    # Allow the use of C++17 `if constexpr` as an extension after C++03
+    "-Wno-c++17-extensions",
 
     # TODO(philnik) This fails with the PSTL.
     "-Wno-unknown-pragmas",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants