`ParseTrailingRequiresClause` currently always creates a synthetic `FunctionPrototypeScope`. This is needed for ordinary function declarators whose prototype scope has already ended, but it is wrong for lambda trailing requires-clauses because they are parsed while the lambda prototype scope is still active. The extra counted scope gives parameters in nested requires-expressions an incorrect function scope depth. Split the synthetic prototype-scope setup from the trailing requires-clause parser so the lambda path can parse the clause in the existing prototype scope. Fixes: #123854 Fixes: #100774
73 lines
1.9 KiB
C++
73 lines
1.9 KiB
C++
// RUN: %clang_cc1 -verify -std=c++2a -fclang-abi-compat=latest -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
|
|
// expected-no-diagnostics
|
|
|
|
template <typename T, int N> concept SmallerThan = sizeof(T) < N;
|
|
template <typename T> concept Small = SmallerThan<T, 1000>;
|
|
|
|
template <typename T> struct X { using type = T; };
|
|
|
|
template <typename T> void f(int n) requires requires {
|
|
// simple-requirement
|
|
T();
|
|
n;
|
|
n == T();
|
|
// compound-requirement
|
|
{T() + 1} -> Small;
|
|
{T() - 1} noexcept;
|
|
{T() * 2} noexcept -> SmallerThan<1234>;
|
|
// type-requirement
|
|
typename T;
|
|
typename X<T>;
|
|
typename X<T>::type;
|
|
typename X<decltype(n)>;
|
|
// nested-requirement
|
|
requires SmallerThan<T, 256>;
|
|
} {}
|
|
// CHECK: define {{.*}}@_Z1fIiEviQrqXcvT__EXfp_Xeqfp_cvS0__EXplcvS0__ELi1ER5SmallXmicvS0__ELi1ENXmlcvS0__ELi2ENR11SmallerThanILi1234EETS0_T1XIS0_ETNS3_4typeETS2_IiEQ11SmallerThanIS0_Li256EEE(
|
|
template void f<int>(int);
|
|
|
|
template <typename T> void g(int n) requires requires (T m) {
|
|
// reference to our parameter vs an enclosing parameter
|
|
n + m;
|
|
} {}
|
|
// CHECK: define {{.*}}@_Z1gIiEviQrQT__XplfL0p_fp_E(
|
|
template void g<int>(int);
|
|
|
|
|
|
namespace GH147650 {
|
|
|
|
template <int> int b;
|
|
template <int b>
|
|
void f()
|
|
requires requires { [] { (void)b; }; } {}
|
|
void test() {
|
|
f<42>();
|
|
}
|
|
// CHECK-LABEL:define {{.*}} void @"_ZN8GH1476501fILi42EEEvvQrqXLNS_3$_0EEE"()
|
|
}
|
|
|
|
namespace GH123854
|
|
{
|
|
|
|
template <class T>
|
|
constexpr auto f() {
|
|
return [] () requires requires (T x) { x; } {};
|
|
}
|
|
|
|
void test() {
|
|
f<int>()();
|
|
}
|
|
// CHECK-LABEL:define {{.*}} void @_ZZN8GH1238541fIiEEDavENKUlvE_clEvQrQT__Xfp_E
|
|
}
|
|
|
|
namespace GH100774 {
|
|
|
|
void test_dependent() {
|
|
auto L = [](auto x) {
|
|
return [w = x](auto) requires requires { w; } {};
|
|
};
|
|
L(0)(1);
|
|
}
|
|
// CHECK-LABEL: define internal void @"_ZZZN8GH10077414test_dependentEvENK3$_0clIiEEDaT_ENKUlS2_E_clIiEEDaS2_QrqXL_ZZZNS_14test_dependentEvENKS0_clES2_E1wEE"
|
|
}
|