Based on post-commit review discussion on 2bd84938470bf2e337801faafb8a67710f46429d with Richard Smith. Other uses of forcing HasEmptyPlaceHolder to false seem OK to me - they're all around pointer/reference types where the pointer/reference token will appear at the rightmost side of the left side of the type name, so they make nested types (eg: the "int" in "int *") behave as though there is a non-empty placeholder (because the "*" is essentially the placeholder as far as the "int" is concerned). This was originally committed in 277623f4d5a672d707390e2c3eaf30a9eb4b075c Reverted in f9ad1d1c775a8e264bebc15d75e0c6e5c20eefc7 due to breakages outside of clang - lldb seems to have some strange/strong dependence on "char [N]" versus "char[N]" when printing strings (not due to that name appearing in DWARF, but probably due to using clang to stringify type names) that'll need to be addressed, plus a few other odds and ends in other subprojects (clang-tools-extra, compiler-rt, etc).
62 lines
2.6 KiB
C++
62 lines
2.6 KiB
C++
// RUN: %clang_cc1 -std=c++2a -verify %s
|
|
|
|
namespace functions
|
|
{
|
|
void foo(int) requires false {}
|
|
// expected-note@-1 3{{because 'false' evaluated to false}}
|
|
// expected-note@-2 {{candidate function not viable: constraints not satisfied}}
|
|
void bar(int) requires true {}
|
|
|
|
void a(int);
|
|
void a(double);
|
|
|
|
void baz() {
|
|
foo(1); // expected-error{{no matching function for call to 'foo'}}
|
|
bar(1);
|
|
void (*p1)(int) = foo; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
|
|
void (*p3)(int) = bar;
|
|
decltype(foo)* a1 = nullptr; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
|
|
decltype(bar)* a2 = nullptr;
|
|
}
|
|
}
|
|
|
|
namespace methods
|
|
{
|
|
template<typename T>
|
|
struct A {
|
|
static void foo(int) requires (sizeof(T) == 1) {} // expected-note 3{{because 'sizeof(char[2]) == 1' (2 == 1) evaluated to false}}
|
|
static void bar(int) requires (sizeof(T) == 2) {} // expected-note 3{{because 'sizeof(char) == 2' (1 == 2) evaluated to false}}
|
|
// Make sure the function body is not instantiated before constraints are checked.
|
|
static auto baz(int) requires (sizeof(T) == 2) { return T::foo(); } // expected-note{{because 'sizeof(char) == 2' (1 == 2) evaluated to false}}
|
|
};
|
|
|
|
void baz() {
|
|
A<char>::foo(1);
|
|
A<char>::bar(1); // expected-error{{invalid reference to function 'bar': constraints not satisfied}}
|
|
A<char>::baz(1); // expected-error{{invalid reference to function 'baz': constraints not satisfied}}
|
|
A<char[2]>::foo(1); // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
|
|
A<char[2]>::bar(1);
|
|
void (*p1)(int) = A<char>::foo;
|
|
void (*p2)(int) = A<char>::bar; // expected-error{{invalid reference to function 'bar': constraints not satisfied}}
|
|
void (*p3)(int) = A<char[2]>::foo; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
|
|
void (*p4)(int) = A<char[2]>::bar;
|
|
decltype(A<char>::foo)* a1 = nullptr;
|
|
decltype(A<char>::bar)* a2 = nullptr; // expected-error{{invalid reference to function 'bar': constraints not satisfied}}
|
|
decltype(A<char[2]>::foo)* a3 = nullptr; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
|
|
decltype(A<char[2]>::bar)* a4 = nullptr;
|
|
}
|
|
}
|
|
|
|
namespace operators
|
|
{
|
|
template<typename T>
|
|
struct A {
|
|
A<T> operator-(A<T> b) requires (sizeof(T) == 1) { return b; } // expected-note{{because 'sizeof(int) == 1' (4 == 1) evaluated to false}}
|
|
};
|
|
|
|
void baz() {
|
|
auto* x = &A<int>::operator-; // expected-error{{invalid reference to function 'operator-': constraints not satisfied}}
|
|
auto y = &A<char>::operator-;
|
|
}
|
|
}
|