summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/decltype.cpp
blob: f1900b2b830f038e2b60bc427aa07c26ad38b788 (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
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s

// PR5290
int const f0();
void f0_test() {
  decltype(0, f0()) i = 0;
  i = 0;
}

struct A { int a[1]; A() { } };
typedef A const AC;
int &f1(int*);
float &f2(int const*);

void test_f2() {
  float &fr = f2(AC().a);
}

template <class T>
struct Future {
  explicit Future(T v);

  template <class F>
  auto call(F&& fn) -> decltype(fn(T())) {
    return fn(T());
  }

  template <class B, class F>
  auto then(F&& fn) -> decltype(call(fn))
  {
    return fn(T());
  }
};

void rdar16527205() {
  Future<int> f1(42);
  f1.call([](int){ return Future<float>(0); });
}

namespace pr10154 {
  class A{
      A(decltype(nullptr) param);
  };
}

template<typename T> struct S {};
template<typename T> auto f(T t) -> decltype(S<int>(t)) {
  using U = decltype(S<int>(t));
  using U = S<int>;
  return S<int>(t);
}

struct B {
  B(decltype(undeclared)); // expected-error {{undeclared identifier}}
};
struct C {
  C(decltype(undeclared; // expected-error {{undeclared identifier}} \
                         // expected-error {{expected ')'}} expected-note {{to match this '('}}
};

namespace PR16529 {
  struct U {};
  template <typename T> struct S {
    static decltype(T{}, U{}) &f();
  };
  U &r = S<int>::f();
}

namespace PR18876 {
  struct A { ~A() = delete; }; // expected-note +{{here}}
  A f();
  decltype(f()) *a; // ok, function call
  decltype(A()) *b; // expected-error {{attempt to use a deleted function}}
  decltype(0, f()) *c; // ok, function call on RHS of comma
  decltype(0, A()) *d; // expected-error {{attempt to use a deleted function}}
  decltype(f(), 0) *e; // expected-error {{attempt to use a deleted function}}
}

template<typename>
class conditional {
};

void foo(conditional<decltype((1),int>) {  // expected-note 2 {{to match this '('}} expected-error {{expected ')'}}
} // expected-error {{expected function body after function declarator}} expected-error 2 {{expected '>'}} expected-error {{expected ')'}}
OpenPOWER on IntegriCloud