File: p4.cpp

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (61 lines) | stat: -rw-r--r-- 2,700 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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-;
  }
}