Skip to content

Allow the use of if constexpr in dialects after C++11. #76178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=======================
Extended C++03 Support
=======================
===================================
Language and Library C++ Extensions
===================================

.. contents::
:local:
Expand All @@ -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
==================================
Expand All @@ -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
=================================
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Design Documents
DesignDocs/AtomicDesign
DesignDocs/CapturingConfigInfo
DesignDocs/ExperimentalFeatures
DesignDocs/ExtendedCXX03Support
DesignDocs/ExtendedCXXSupport
DesignDocs/FeatureTestMacros
DesignDocs/FileTimeType
DesignDocs/HeaderRemovalPolicy
Expand Down
31 changes: 31 additions & 0 deletions libcxx/test/libcxx/extensions/test-cxx17-extensions.pass.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions libcxx/utils/libcxx/test/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down