File: p1.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (76 lines) | stat: -rw-r--r-- 2,394 bytes parent folder | download | duplicates (30)
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
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s

// C++1z [temp.local]p1:
//   Like normal (non-template) classes, class templates have an
//   injected-class-name (Clause 9). The injected-class-name can
//   be used as a template-name or a type-name.

template<typename> char id;

template<typename> struct TempType {};
template<template<typename> class> struct TempTemp {};

template<typename> void use(int&); // expected-note {{invalid explicitly-specified argument}} expected-note {{no known conversion}}
template<template<typename> class> void use(float&); // expected-note 2{{no known conversion}}
template<int> void use(char&); // expected-note 2{{invalid explicitly-specified argument}}

template<typename T> struct A {
  template<typename> struct C {};
  struct B : C<T> {
    //   When it is used with a template-argument-list,
    A<int> *aint;
    typename B::template C<int> *cint;

    //   as a template-argument for a template template-parameter,
    TempTemp<A> a_as_temp;
    TempTemp<B::template C> c_as_temp;

    //   or as the final identifier in the elaborated-type-specifier of a friend
    //   class template declaration,
    template<typename U> friend struct A;
    // it refers to the class template itself.

    // Otherwise, it is equivalent to the template-name followed by the
    // template-parameters of the class template enclosed in <>.
    A *aT;
    typename B::C *cT;
    TempType<A> a_as_type;
    TempType<typename B::C> c_as_type;
    friend struct A;
    friend struct B::C;

    void f(T &t) {
      use<A>(t); // expected-error {{no matching function}}
      if constexpr (&id<T> != &id<int>)
        use<B::template C>(t); // expected-error {{no matching function}}
    }
  };
};

template struct A<int>;
template struct A<float>;
template struct A<char>; // expected-note {{instantiation of}}

template <typename T> struct X0 {
  X0();
  ~X0();
  X0 f(const X0&);
};

// Test non-type template parameters.
template <int N1, const int& N2, const int* N3> struct X1 {
  X1();
  ~X1();
  X1 f(const X1& x1a) { X1 x1b(x1a); return x1b; }
};

//   When it is used with a template-argument-list, it refers to the specified
//   class template specialization, which could be the current specialization
//   or another specialization.
// FIXME: Test this clause.

int i = 42;
void test() {
  X0<int> x0; (void)x0;
  X1<42, i, &i> x1; (void)x1;
}