-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[libc][utils] cpp::always_false to enable static_assert(false) #66209
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libc ChangesNone -- Full diff: https://github.com//pull/66209.diff4 Files Affected:
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt index d24c023ec28ebc9..4e3e4a3edf381d2 100644 --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -95,6 +95,7 @@ add_header_library( type_traits HDRS type_traits.h + type_traits/always_false.h type_traits/add_lvalue_reference.h type_traits/add_pointer.h type_traits/add_rvalue_reference.h diff --git a/libc/src/__support/CPP/type_traits/always_false.h b/libc/src/__support/CPP/type_traits/always_false.h new file mode 100644 index 000000000000000..84be58d16ec8da6 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/always_false.h @@ -0,0 +1,25 @@ +//===-- convenient static_assert(false) helper ------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H + +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// This is technically not part of the standard but it come often enough that +// it's convenient to have around. +// +// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2593r0.html#valid-workaround + +template <typename...> LIBC_INLINE_VAR constexpr bool always_false = false; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H diff --git a/libc/src/__support/CPP/utility/declval.h b/libc/src/__support/CPP/utility/declval.h index 9261ceb9332d518..21bb973de0dd048 100644 --- a/libc/src/__support/CPP/utility/declval.h +++ b/libc/src/__support/CPP/utility/declval.h @@ -9,17 +9,13 @@ #define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_DECLVAL_H #include "src/__support/CPP/type_traits/add_rvalue_reference.h" -#include "src/__support/macros/attributes.h" +#include "src/__support/CPP/type_traits/always_false.h" namespace __llvm_libc::cpp { // declval -namespace detail { -template <typename T> LIBC_INLINE_VAR constexpr bool always_false = false; -} - template <typename T> cpp::add_rvalue_reference_t<T> declval() { - static_assert(detail::always_false<T>, + static_assert(cpp::always_false<T>, "declval not allowed in an evaluated context"); } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 17e4913749d51c6..160998049fcd2a8 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -289,6 +289,7 @@ libc_support_library( "src/__support/CPP/type_traits/add_lvalue_reference.h", "src/__support/CPP/type_traits/add_pointer.h", "src/__support/CPP/type_traits/add_rvalue_reference.h", + "src/__support/CPP/type_traits/always_false.h", "src/__support/CPP/type_traits/bool_constant.h", "src/__support/CPP/type_traits/conditional.h", "src/__support/CPP/type_traits/decay.h", |
legrosbuffle
approved these changes
Sep 13, 2023
kstoimenov
pushed a commit
to kstoimenov/llvm-project
that referenced
this pull request
Sep 14, 2023
This was referenced Sep 14, 2023
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.