1 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
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
7 decltype(h1
) h1() { // expected-error {{use of undeclared identifier 'h1'}}
15 auto f3() { return void(); }
18 return; // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
22 return void(); // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
26 auto l2
= []() { return; };
27 auto l3
= []() { return void(); };
30 return; // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}}
34 return void(); // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}}
37 } // namespace JustAuto
39 namespace DecltypeAuto
{
41 decltype(auto) f1() { }
42 decltype(auto) f2() { return; }
43 decltype(auto) f3() { return void(); }
46 return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
50 return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
53 auto l1
= []() -> decltype(auto) { };
54 auto l2
= []() -> decltype(auto) { return; };
55 auto l3
= []() -> decltype(auto) { return void(); };
56 auto l4
= []() -> decltype(auto) {
58 return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
60 auto l5
= []() -> decltype(auto) {
62 return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
65 } // namespace DecltypeAuto
69 auto *f1() { } // expected-error {{cannot deduce return type 'auto *' for function with no return statements}}
71 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
74 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
78 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
82 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
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}}
89 auto l3
= []() -> auto* {
90 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
92 auto l4
= []() -> auto* {
94 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
96 auto l5
= []() -> auto* {
98 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
100 } // namespace AutoPtr
104 auto& f1() { // expected-error {{cannot deduce return type 'auto &' for function with no return statements}}
107 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
110 return void(); // expected-error@-1 {{cannot form a reference to 'void'}}
114 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
118 return void(); // expected-error {{deduced as 'int' in earlier return statement}}
120 auto& f6() { return 42; } // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
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}}
126 auto l3
= []() -> auto& { // expected-error {{cannot form a reference to 'void'}}
129 auto l4
= []() -> auto& {
131 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
133 auto l5
= []() -> auto & {
135 return void(); // expected-error {{deduced as 'int' in earlier return statement}}
137 auto l6
= []() -> auto& {
138 return 42; // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
140 } // namespace AutoRef