summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate/temp_arg_template_cxx1z.cpp
blob: aa517c32859937e2bec2e267ce06f562f7b6314c (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -frelaxed-template-template-args %s

// expected-note@temp_arg_template_cxx1z.cpp:* 1+{{}}

template<template<int> typename> struct Ti;
template<template<int...> typename> struct TPi;
template<template<int, int...> typename> struct TiPi;
template<template<int..., int...> typename> struct TPiPi; // FIXME: Why is this not ill-formed?

template<typename T, template<T> typename> struct tT0;
template<template<typename T, T> typename> struct Tt0;

template<template<typename> typename> struct Tt;
template<template<typename, typename...> typename> struct TtPt;

template<int> struct i;
template<int, int = 0> struct iDi;
template<int, int> struct ii;
template<int...> struct Pi;
template<int, int, int...> struct iiPi;

template<int, typename = int> struct iDt;
template<int, typename> struct it;

template<typename T, T v> struct t0;

template<typename...> struct Pt;

namespace IntParam {
  using ok = Pt<Ti<i>,
        Ti<iDi>,
        Ti<Pi>,
        Ti<iDt>>;
  using err1 = Ti<ii>; // expected-error {{different template parameters}}
  using err2 = Ti<iiPi>; // expected-error {{different template parameters}}
  using err3 = Ti<t0>; // expected-error {{different template parameters}}
  using err4 = Ti<it>; // expected-error {{different template parameters}}
}

// These are accepted by the backwards-compatibility "parameter pack in
// parameter matches any number of parameters in arguments" rule.
namespace IntPackParam {
  using ok = TPi<Pi>;
  using ok_compat = Pt<TPi<i>, TPi<iDi>, TPi<ii>, TPi<iiPi>>;
  using err1 = TPi<t0>; // expected-error {{different template parameters}}
  using err2 = TPi<iDt>; // expected-error {{different template parameters}}
  using err3 = TPi<it>; // expected-error {{different template parameters}}
}

namespace IntAndPackParam {
  using ok = TiPi<Pi>;
  using ok_compat = Pt<TiPi<ii>, TiPi<iDi>, TiPi<iiPi>>;
  using err = TiPi<iDi>;
}

namespace DependentType {
  using ok = Pt<tT0<int, i>, tT0<int, iDi>>;
  using err1 = tT0<int, ii>; // expected-error {{different template parameters}}
  using err2 = tT0<short, i>; // FIXME: should this be OK?
  using err2a = tT0<long long, i>; // FIXME: should this be OK (if long long is larger than int)?
  using err2b = tT0<void*, i>; // expected-error {{different template parameters}}
  using err3 = tT0<short, t0>; // expected-error {{different template parameters}}

  using ok2 = Tt0<t0>;
  using err4 = Tt0<it>; // expected-error {{different template parameters}}
}

namespace Auto {
  template<template<int> typename T> struct TInt {};
  template<template<int*> typename T> struct TIntPtr {};
  template<template<auto> typename T> struct TAuto {};
  template<template<auto*> typename T> struct TAutoPtr {};
  template<template<decltype(auto)> typename T> struct TDecltypeAuto {};
  template<auto> struct Auto;
  template<auto*> struct AutoPtr;
  template<decltype(auto)> struct DecltypeAuto;
  template<int> struct Int;
  template<int*> struct IntPtr;

  TInt<Auto> ia;
  TInt<AutoPtr> iap; // expected-error {{different template parameters}}
  TInt<DecltypeAuto> ida; // FIXME expected-error {{different template parameters}}
  TInt<Int> ii;
  TInt<IntPtr> iip; // expected-error {{different template parameters}}

  TIntPtr<Auto> ipa;
  TIntPtr<AutoPtr> ipap;
  TIntPtr<DecltypeAuto> ipda; // FIXME expected-error {{different template parameters}}
  TIntPtr<Int> ipi; // expected-error {{different template parameters}}
  TIntPtr<IntPtr> ipip;

  TAuto<Auto> aa;
  TAuto<AutoPtr> aap; // expected-error {{different template parameters}}
  TAuto<Int> ai; // expected-error {{different template parameters}}
  TAuto<IntPtr> aip; // expected-error {{different template parameters}}

  TAutoPtr<Auto> apa;
  TAutoPtr<AutoPtr> apap;
  TAutoPtr<Int> api; // expected-error {{different template parameters}}
  TAutoPtr<IntPtr> apip; // expected-error {{different template parameters}}

  TDecltypeAuto<DecltypeAuto> dada;
  TDecltypeAuto<Int> dai; // expected-error {{different template parameters}}
  TDecltypeAuto<IntPtr> daip; // expected-error {{different template parameters}}

  // FIXME: It's completely unclear what should happen here. A case can be made
  // that 'auto' is more specialized, because it's always a prvalue, whereas
  // 'decltype(auto)' could have any value category. Under that interpretation,
  // we get the following results entirely backwards:
  TAuto<DecltypeAuto> ada; // expected-error {{different template parameters}}
  TAutoPtr<DecltypeAuto> apda; // expected-error {{different template parameters}}
  TDecltypeAuto<Auto> daa;
  TDecltypeAuto<AutoPtr> daa; // expected-error {{different template parameters}}

  int n;
  template<auto A, decltype(A) B = &n> struct SubstFailure;
  TInt<SubstFailure> isf; // expected-error {{different template parameters}}
  TIntPtr<SubstFailure> ipsf; // expected-error {{different template parameters}}
}