File: cxx2c-variadic-friends.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,235,796 kB
  • sloc: cpp: 7,617,614; ansic: 1,433,901; asm: 1,058,726; python: 252,096; f90: 94,671; objc: 70,753; lisp: 42,813; pascal: 18,401; sh: 10,032; ml: 5,111; perl: 4,720; awk: 3,523; makefile: 3,401; javascript: 2,272; xml: 892; fortran: 770
file content (91 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (4)
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
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c %s

template <typename> struct TS; // #template

struct Errors {
  friend int, int;
  friend int, long, char;

  // We simply diagnose and ignore the '...' here.
  friend float...; // expected-error {{pack expansion does not contain any unexpanded parameter packs}}

  friend short..., unsigned, unsigned short...; // expected-error 2 {{pack expansion does not contain any unexpanded parameter packs}}

  template <typename>
  friend struct TS, int; // expected-error {{a friend declaration that befriends a template must contain exactly one type-specifier}}

  double friend; // expected-error {{'friend' must appear first in a non-function declaration}}
  double friend, double; // expected-error {{expected member name or ';' after declaration specifiers}}
};

template <typename>
struct C { template<class T> class Nested; };

template <typename, typename>
struct D { template<class T> class Nested; };

template <bool>
struct E { template<class T> class Nested; };

template<class... Ts> // expected-note {{template parameter is declared here}}
struct VS {
  friend Ts...;

  friend class Ts...; // expected-error {{declaration of 'Ts' shadows template parameter}}
  // expected-error@-1 {{pack expansion does not contain any unexpanded parameter packs}}

  // TODO: Fix-it hint to insert '...'.
  friend Ts; // expected-error {{friend declaration contains unexpanded parameter pack}}

  template<class... Us>
  friend Us...; // expected-error {{friend type templates must use an elaborated type}}

  template<class... Us> // expected-note {{is declared here}}
  friend class Us...; // expected-error {{declaration of 'Us' shadows template parameter}}

  template<class U>
  friend class C<Ts>::template Nested<U>...; // expected-error {{cannot specialize a dependent template}}

  template<class... Us>
  friend class C<Ts...>::template Nested<Us>...; // expected-error {{cannot specialize a dependent template}}

  // Nonsense (see CWG 2917).
  template<class... Us>
  friend class C<Us>::Nested...; // expected-error {{friend declaration expands pack 'Us' that is declared it its own template parameter list}}

  template<bool... Bs>
  friend class E<Bs>::Nested...; // expected-error {{friend declaration expands pack 'Bs' that is declared it its own template parameter list}}

  // FIXME: Both of these should be valid, but we can't handle these at
  // the moment because the NNS is dependent.
  template<class ...T>
  friend class TS<Ts>::Nested...; // expected-warning {{dependent nested name specifier 'TS<Ts>' for friend template declaration is not supported; ignoring this friend declaration}}

  template<class T>
  friend class D<T, Ts>::Nested...; // expected-warning {{dependent nested name specifier 'D<T, Ts>' for friend class declaration is not supported; turning off access control for 'VS'}}
};

namespace length_mismatch {
struct A {
  template <typename...>
  struct Nested {
    struct Foo{};
  };
};
template <typename ...Ts>
struct S {
  template <typename ...Us>
  struct T {
    // expected-error@+2 {{pack expansion contains parameter packs 'Ts' and 'Us' that have different lengths (1 vs. 2)}}
    // expected-error@+1 {{pack expansion contains parameter packs 'Ts' and 'Us' that have different lengths (2 vs. 1)}}
    friend class Ts::template Nested<Us>::Foo...;
  };
};

void f() {
  S<A>::T<int> s;
  S<A, A>::T<int, long> s2;
  S<A>::T<int, long> s3; // expected-note {{in instantiation of}}
  S<A, A>::T<int> s4; // expected-note {{in instantiation of}}
}
}