summaryrefslogtreecommitdiff
path: root/test/SemaCXX/trailing-return-0x.cpp
blob: c6b22c54be0c1a8dc9e181ad9de81bf6417d686a (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
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s

template <class T>
struct only
{
    only(T) {}

    template <class U>
    only(U)
    {
        static_assert(sizeof(U) == 0, "expected type failure");
    }
};

auto f() -> int
{
    return 0;
}

auto g(); // expected-error{{return without trailing return type; deduced return types are a C++14 extension}}
decltype(auto) g2(); // expected-warning{{extension}} expected-error-re{{{{^}}deduced return types are a C++14 extension}}
auto badness = g2();

int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}}

int i();
auto i() -> int;
int i() {}

using T = auto (int) -> auto (*)(char) -> void; // expected-note {{previous}}
using T = void; // expected-error {{type alias redefinition with different types ('void' vs 'auto (int) -> auto (*)(char) -> void')}}

using U = auto (int) -> auto (*)(char) -> void;
using U = void (*(int))(char); // ok

int x;

template <class T>
auto i(T x) -> decltype(x)
{
    return x;
}

only<double> p1 = i(1.0);

template <class T>
struct X
{
    auto f(T x) -> T { return x; }

    template <class U>
    auto g(T x, U y) -> decltype(x + y)
    {
        return x + y;
    }

  template<typename U>
  struct nested {
    template <class V>
    auto h(T x, U y, V z) -> decltype(x + y + z)
    {
        return x + y + z;
    }
  };

  template<typename U>
  nested<U> get_nested();
};

X<int> xx;
only<int> p2 = xx.f(0L);
only<double> p3 = xx.g(0L, 1.0);
only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f);

namespace PR12053 {
  template <typename T>
  auto f1(T t) -> decltype(f1(t)) {} // expected-note{{candidate template ignored}}

  void test_f1() {
    f1(0); // expected-error{{no matching function for call to 'f1'}}
  }

  template <typename T>
  auto f2(T t) -> decltype(f2(&t)) {} // expected-note{{candidate template ignored}}

  void test_f2() {
    f2(0); // expected-error{{no matching function for call to 'f2'}}
  }
}

namespace DR1608 {
  struct S {
    void operator+();
    int operator[](int);
    auto f() -> decltype(+*this); // expected-note {{here}}
    auto f() -> decltype((*this)[0]); // expected-error {{cannot be overloaded}}
  };
}

namespace PR16273 {
  struct A {
    template <int N> void f();
    auto g()->decltype(this->f<0>());
  };
}