File: cxx2a-constrained-template-param.cpp

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (70 lines) | stat: -rw-r--r-- 1,744 bytes parent folder | download | duplicates (12)
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
62
63
64
65
66
67
68
69
70
// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify

namespace type
{
  template<typename T>
  concept C1 = true;

  template<C1 T, C1 U = int>
  using A = T[10];

  using a = A<int>;

  namespace ns {
    template<typename T, int a = 0>
    concept C2 = true;
  }

  template<ns::C2 T1, ::type::ns::C2 T2> requires (sizeof(T1) <= sizeof(T2))
  struct B { };

  using b = B<int, int>;

  template<ns::C2... T1>
  struct C { };

  using c1 = C<char, char, char>;
  using c2 = C<char, char, char, char>;
}

namespace non_type
{
  template<int v>
  concept C1 = true;

  template<C1 v, C1 u = 0> // expected-error{{expected a type}} // expected-note{{declared here}}
  // expected-error@-1 2{{concept named in type constraint is not a type concept}}
  // expected-error@-2 {{expected ',' or '>' in template-parameter-list}}
  int A = v; // expected-error{{'v' does not refer to a value}}
}

namespace temp
{
  template<typename>
  struct test1 { }; // expected-note{{template is declared here}}

  template<template<typename> typename T>
  concept C1 = true;

  template<C1 TT, C1 UU = test1> // expected-error{{use of class template 'test1' requires template arguments}}
  // expected-error@-1 2{{concept named in type constraint is not a type concept}}
  using A = TT<int>; // expected-error{{expected ';' after alias declaration}}
}

namespace PR67235 {

template <class T>
concept C = true;

template <auto D>
struct S {};

// Don't destroy annotation 'C' at the end of the lambda; else we'll run into a
// use-after-free bug while constructing the type constraint 'C' on 'Default'.
template <typename Ret, C Default = decltype([] { return Ret(); })>
void func() {}

template <typename Ret, C Default = S<[] { return Ret(); }>>
void func2() {}

}