summaryrefslogtreecommitdiffstats
path: root/clang/test/CXX/expr/expr.prim
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/expr/expr.prim')
-rw-r--r--clang/test/CXX/expr/expr.prim/expr.prim.id/mixed-constraints.cpp18
-rw-r--r--clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp58
-rw-r--r--clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.closure/p3.cpp20
3 files changed, 96 insertions, 0 deletions
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.id/mixed-constraints.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.id/mixed-constraints.cpp
new file mode 100644
index 00000000000..fafb3f7b35d
--- /dev/null
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.id/mixed-constraints.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+
+template<typename T> requires (sizeof(T) >= 4 && sizeof(T) <= 10)
+// expected-note@-1{{because 'sizeof(char [20]) <= 10' (20 <= 10) evaluated to false}}
+// expected-note@-2{{because 'sizeof(char) >= 4' (1 >= 4) evaluated to false}}
+void foo() requires (sizeof(T) <= 8) {}
+// expected-note@-1{{candidate template ignored: constraints not satisfied [with T = char]}}
+// expected-note@-2{{candidate template ignored: constraints not satisfied [with T = char [9]]}}
+// expected-note@-3{{candidate template ignored: constraints not satisfied [with T = char [20]]}}
+// expected-note@-4{{because 'sizeof(char [9]) <= 8' (9 <= 8) evaluated to false}}
+
+void bar() {
+ foo<char>(); // expected-error{{no matching function for call to 'foo'}}
+ foo<int>();
+ foo<unsigned long long int>();
+ foo<char[9]>(); // expected-error{{no matching function for call to 'foo'}}
+ foo<char[20]>(); // expected-error{{no matching function for call to 'foo'}}
+} \ No newline at end of file
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp
new file mode 100644
index 00000000000..f13ab279da3
--- /dev/null
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -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}}
+ };
+
+ void baz() {
+ A<char>::foo(1);
+ A<char>::bar(1); // expected-error{{invalid reference to function 'bar': 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-;
+ }
+} \ No newline at end of file
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.closure/p3.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.closure/p3.cpp
new file mode 100644
index 00000000000..942280e1059
--- /dev/null
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.closure/p3.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+
+auto l1 = [] (auto x) requires (sizeof(decltype(x)) == 1) { return x; };
+// expected-note@-1{{candidate template ignored: constraints not satisfied [with $0 = int]}}
+// expected-note@-2{{because 'sizeof(decltype(x)) == 1' (4 == 1) evaluated to false}}
+
+auto l1t1 = l1('a');
+auto l1t2 = l1(1);
+// expected-error@-1{{no matching function for call to object of type '(lambda at}}
+
+auto l2 = [] (auto... x) requires ((sizeof(decltype(x)) >= 2) && ...) { return (x + ...); };
+// expected-note@-1{{candidate template ignored: constraints not satisfied [with $0 = <char>]}}
+// expected-note@-2{{candidate template ignored: constraints not satisfied [with $0 = <int, char>]}}
+// expected-note@-3 2{{because 'sizeof(decltype(x)) >= 2' (1 >= 2) evaluated to false}}
+
+auto l2t1 = l2('a');
+// expected-error@-1{{no matching function for call to object of type '(lambda at}}
+auto l2t2 = l2(1, 'a');
+// expected-error@-1{{no matching function for call to object of type '(lambda at}}
+auto l2t3 = l2((short)1, (short)1); \ No newline at end of file
OpenPOWER on IntegriCloud