| 1 |
// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s |
| 3 |
|
| 4 |
// Check that we don't get any extra warning for "return" without an |
| 5 |
// expression, in a function that might have been intended to return |
| 6 |
// void all along. |
| 7 |
decltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}} |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
namespace JustAuto { |
| 12 |
int i; |
| 13 |
auto f1() { } |
| 14 |
auto f2() { return; } |
| 15 |
auto f3() { return void(); } |
| 16 |
auto f4() { |
| 17 |
return i; |
| 18 |
return; // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} |
| 19 |
} |
| 20 |
auto f5() { |
| 21 |
return i; |
| 22 |
return void(); // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} |
| 23 |
} |
| 24 |
|
| 25 |
auto l1 = []() { }; |
| 26 |
auto l2 = []() { return; }; |
| 27 |
auto l3 = []() { return void(); }; |
| 28 |
auto l4 = []() { |
| 29 |
return i; |
| 30 |
return; // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}} |
| 31 |
}; |
| 32 |
auto l5 = []() { |
| 33 |
return i; |
| 34 |
return void(); // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}} |
| 35 |
}; |
| 36 |
|
| 37 |
} // namespace JustAuto |
| 38 |
|
| 39 |
namespace DecltypeAuto { |
| 40 |
int i; |
| 41 |
decltype(auto) f1() { } |
| 42 |
decltype(auto) f2() { return; } |
| 43 |
decltype(auto) f3() { return void(); } |
| 44 |
decltype(auto) f4() { |
| 45 |
return i; |
| 46 |
return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} |
| 47 |
} |
| 48 |
decltype(auto) f5() { |
| 49 |
return i; |
| 50 |
return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} |
| 51 |
} |
| 52 |
|
| 53 |
auto l1 = []() -> decltype(auto) { }; |
| 54 |
auto l2 = []() -> decltype(auto) { return; }; |
| 55 |
auto l3 = []() -> decltype(auto) { return void(); }; |
| 56 |
auto l4 = []() -> decltype(auto) { |
| 57 |
return i; |
| 58 |
return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} |
| 59 |
}; |
| 60 |
auto l5 = []() -> decltype(auto) { |
| 61 |
return i; |
| 62 |
return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} |
| 63 |
}; |
| 64 |
|
| 65 |
} // namespace DecltypeAuto |
| 66 |
|
| 67 |
namespace AutoPtr { |
| 68 |
int i; |
| 69 |
auto *f1() { } // expected-error {{cannot deduce return type 'auto *' for function with no return statements}} |
| 70 |
auto *f2() { |
| 71 |
return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} |
| 72 |
} |
| 73 |
auto *f3() { |
| 74 |
return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} |
| 75 |
} |
| 76 |
auto *f4() { |
| 77 |
return &i; |
| 78 |
return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} |
| 79 |
} |
| 80 |
auto *f5() { |
| 81 |
return &i; |
| 82 |
return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} |
| 83 |
} |
| 84 |
|
| 85 |
auto l1 = []() -> auto* { }; // expected-error {{cannot deduce return type 'auto *' for function with no return statements}} |
| 86 |
auto l2 = []() -> auto* { |
| 87 |
return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} |
| 88 |
}; |
| 89 |
auto l3 = []() -> auto* { |
| 90 |
return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} |
| 91 |
}; |
| 92 |
auto l4 = []() -> auto* { |
| 93 |
return &i; |
| 94 |
return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} |
| 95 |
}; |
| 96 |
auto l5 = []() -> auto* { |
| 97 |
return &i; |
| 98 |
return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} |
| 99 |
}; |
| 100 |
} // namespace AutoPtr |
| 101 |
|
| 102 |
namespace AutoRef { |
| 103 |
int i; |
| 104 |
auto& f1() { // expected-error {{cannot deduce return type 'auto &' for function with no return statements}} |
| 105 |
} |
| 106 |
auto& f2() { |
| 107 |
return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} |
| 108 |
} |
| 109 |
auto& f3() { |
| 110 |
return void(); // expected-error@-1 {{cannot form a reference to 'void'}} |
| 111 |
} |
| 112 |
auto& f4() { |
| 113 |
return i; |
| 114 |
return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} |
| 115 |
} |
| 116 |
auto& f5() { |
| 117 |
return i; |
| 118 |
return void(); // expected-error {{deduced as 'int' in earlier return statement}} |
| 119 |
} |
| 120 |
auto& f6() { return 42; } // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} |
| 121 |
|
| 122 |
auto l1 = []() -> auto& { }; // expected-error {{cannot deduce return type 'auto &' for function with no return statements}} |
| 123 |
auto l2 = []() -> auto& { |
| 124 |
return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} |
| 125 |
}; |
| 126 |
auto l3 = []() -> auto& { // expected-error {{cannot form a reference to 'void'}} |
| 127 |
return void(); |
| 128 |
}; |
| 129 |
auto l4 = []() -> auto& { |
| 130 |
return i; |
| 131 |
return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} |
| 132 |
}; |
| 133 |
auto l5 = []() -> auto & { |
| 134 |
return i; |
| 135 |
return void(); // expected-error {{deduced as 'int' in earlier return statement}} |
| 136 |
}; |
| 137 |
auto l6 = []() -> auto& { |
| 138 |
return 42; // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} |
| 139 |
}; |
| 140 |
} // namespace AutoRef |