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 -decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT; +template +decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT { + static_assert(_False, "Calling declval is ill-formed, see [declval]/2."); +} _LIBCPP_END_NAMESPACE_STD Index: libcxx/test/std/utilities/utility/declval/declval.compile.fail.cpp =================================================================== --- /dev/null +++ libcxx/test/std/utilities/utility/declval/declval.compile.fail.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// template typename add_rvalue_reference::type declval() noexcept; + +#include + +int main() { + if (false) { + int i = std::declval(); + } + + return 0; +}