[libcxx-commits] [PATCH] D145376: [libc++] add declval failure assertion for instantiation
Igor Zhukov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 6 07:24:50 PST 2023
fsb4000 updated this revision to Diff 502642.
fsb4000 added a comment.
change a `compile.fail` test to a `verify` test
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145376/new/
https://reviews.llvm.org/D145376
Files:
libcxx/include/__utility/declval.h
libcxx/test/std/utilities/utility/declval/declval.verify.cpp
Index: libcxx/test/std/utilities/utility/declval/declval.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/utilities/utility/declval/declval.verify.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <utility>
+
+// template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
+
+#include <utility>
+
+int main() {
+ if (false) {
+ int i = std::declval<int>(); // expected-warning@*:* {{code will never be executed}}
+ (void)i;
+ }
+
+ return 0;
+}
+// expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Calling declval is ill-formed, see [declval]/2.}}
Index: libcxx/include/__utility/declval.h
===================================================================
--- libcxx/include/__utility/declval.h
+++ libcxx/include/__utility/declval.h
@@ -26,8 +26,10 @@
_Tp __declval(long);
_LIBCPP_SUPPRESS_DEPRECATED_POP
-template <class _Tp>
-decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT;
+template <class _Tp, bool _False = false>
+decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT {
+ static_assert(_False, "Calling declval is ill-formed, see [declval]/2.");
+}
_LIBCPP_END_NAMESPACE_STD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145376.502642.patch
Type: text/x-patch
Size: 1569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230306/64123ad0/attachment-0001.bin>
More information about the libcxx-commits
mailing list