[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / trailing-return-0x.cpp
blob4834aaf5277a885321d8f492d3015d63a9683435
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 template <class T>
4 struct only
6 only(T) {}
8 template <class U>
9 only(U)
11 static_assert(sizeof(U) == 0, "expected type failure");
15 auto f() -> int
17 return 0;
20 auto g(); // expected-error{{return without trailing return type; deduced return types are a C++14 extension}}
21 decltype(auto) g2(); // expected-warning{{extension}} expected-error-re{{{{^}}deduced return types are a C++14 extension}}
22 auto badness = g2();
24 int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}}
26 int i();
27 auto i() -> int;
28 int i() {}
30 using T = auto (int) -> auto (*)(char) -> void; // expected-note {{previous}}
31 using T = void; // expected-error {{type alias redefinition with different types ('void' vs 'auto (int) -> auto (*)(char) -> void')}}
33 using U = auto (int) -> auto (*)(char) -> void;
34 using U = void (*(int))(char); // ok
36 int x;
38 template <class T>
39 auto i(T x) -> decltype(x)
41 return x;
44 only<double> p1 = i(1.0);
46 template <class T>
47 struct X
49 auto f(T x) -> T { return x; }
51 template <class U>
52 auto g(T x, U y) -> decltype(x + y)
54 return x + y;
57 template<typename U>
58 struct nested {
59 template <class V>
60 auto h(T x, U y, V z) -> decltype(x + y + z)
62 return x + y + z;
66 template<typename U>
67 nested<U> get_nested();
70 X<int> xx;
71 only<int> p2 = xx.f(0L);
72 only<double> p3 = xx.g(0L, 1.0);
73 only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f);
75 namespace PR12053 {
76 template <typename T>
77 auto f1(T t) -> decltype(f1(t)) {} // expected-note{{candidate template ignored}}
79 void test_f1() {
80 f1(0); // expected-error{{no matching function for call to 'f1'}}
83 template <typename T>
84 auto f2(T t) -> decltype(f2(&t)) {} // expected-note{{candidate template ignored}}
86 void test_f2() {
87 f2(0); // expected-error{{no matching function for call to 'f2'}}
91 namespace DR1608 {
92 struct S {
93 void operator+();
94 int operator[](int);
95 auto f() -> decltype(+*this); // expected-note {{here}}
96 auto f() -> decltype((*this)[0]); // expected-error {{cannot be overloaded}}
100 namespace PR16273 {
101 struct A {
102 template <int N> void f();
103 auto g()->decltype(this->f<0>());
107 namespace PR46637 {
108 using A = auto () -> auto; // expected-error {{'auto' not allowed in function return type}}
109 using B = auto (*)() -> auto; // expected-error {{'auto' not allowed in function return type}}
110 template<auto (*)() -> auto> struct X {}; // expected-error {{'auto' not allowed in function return type}}
111 template<typename T> struct Y { T x; };
112 Y<auto() -> auto> y; // expected-error {{'auto' not allowed in function return type}}