brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · cb63c2e Raw
59 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -verify %s2 3template <class T>4struct A {5  void primary();6};7 8template <class T>9  requires requires(T &t) { requires sizeof(t) > 4; }10struct A<T> {11  void specialization1();12};13 14template <class T>15  requires requires(T &t) { requires sizeof(t) > 8; }16struct A<T> {17  void specialization2();18};19 20int main() {21  A<char>().primary();22  A<char[5]>().specialization1();23  A<char[16]>(); // expected-error {{ambiguous partial specialization}}24                 // expected-note@10 {{partial specialization matches [with T = char[16]}}25                 // expected-note@16 {{partial specialization matches [with T = char[16]}}26}27 28// Check error messages when no overload with constraints matches.29template <class T>30void foo()31  requires requires(T &t) { requires sizeof(t) < 4; }32{}33 34template <class T>35void foo()36  requires requires(T &t) { requires sizeof(t) > 4; }37{}38 39template <class T>40void foo()41  requires requires(T &t) { requires sizeof(t) > 8; }42{}43 44void test() {45  foo<char[4]>();46  // expected-error@-1 {{no matching function for call to 'foo'}}47  // expected-note@30 {{candidate template ignored: constraints not satisfied}}48  // expected-note@31 {{because 'sizeof (t) < 4' (4 < 4) evaluated to false}}49  // expected-note@35 {{candidate template ignored: constraints not satisfied}}50  // expected-note@36 {{because 'sizeof (t) > 4' (4 > 4) evaluated to false}}51  // expected-note@40 {{candidate template ignored: constraints not satisfied}}52  // expected-note@41 {{because 'sizeof (t) > 8' (4 > 8) evaluated to false}}53 54  foo<char[16]>();55  // expected-error@-1 {{call to 'foo' is ambiguous}}56  // expected-note@35 {{candidate function}}57  // expected-note@40 {{candidate function}}58}59