13c8d2aa8SArthur O'Dwyer // RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
23c8d2aa8SArthur O'Dwyer // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
33c8d2aa8SArthur O'Dwyer
43c8d2aa8SArthur O'Dwyer // Check that we don't get any extra warning for "return" without an
53c8d2aa8SArthur O'Dwyer // expression, in a function that might have been intended to return
63c8d2aa8SArthur O'Dwyer // void all along.
h1()73c8d2aa8SArthur O'Dwyer decltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}}
83c8d2aa8SArthur O'Dwyer return;
93c8d2aa8SArthur O'Dwyer }
107adb8588SArthur O'Dwyer
117adb8588SArthur O'Dwyer namespace JustAuto {
127adb8588SArthur O'Dwyer int i;
f1()137adb8588SArthur O'Dwyer auto f1() { }
f2()147adb8588SArthur O'Dwyer auto f2() { return; }
f3()157adb8588SArthur O'Dwyer auto f3() { return void(); }
f4()167adb8588SArthur O'Dwyer auto f4() {
177adb8588SArthur O'Dwyer return i;
187adb8588SArthur O'Dwyer return; // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
197adb8588SArthur O'Dwyer }
f5()207adb8588SArthur O'Dwyer auto f5() {
217adb8588SArthur O'Dwyer return i;
227adb8588SArthur O'Dwyer return void(); // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
237adb8588SArthur O'Dwyer }
247adb8588SArthur O'Dwyer
__anon22edc4580102() 257adb8588SArthur O'Dwyer auto l1 = []() { };
__anon22edc4580202() 267adb8588SArthur O'Dwyer auto l2 = []() { return; };
__anon22edc4580302() 277adb8588SArthur O'Dwyer auto l3 = []() { return void(); };
__anon22edc4580402() 287adb8588SArthur O'Dwyer auto l4 = []() {
297adb8588SArthur O'Dwyer return i;
307adb8588SArthur O'Dwyer return; // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}}
317adb8588SArthur O'Dwyer };
__anon22edc4580502() 327adb8588SArthur O'Dwyer auto l5 = []() {
337adb8588SArthur O'Dwyer return i;
347adb8588SArthur O'Dwyer return void(); // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}}
357adb8588SArthur O'Dwyer };
367adb8588SArthur O'Dwyer
377adb8588SArthur O'Dwyer } // namespace JustAuto
387adb8588SArthur O'Dwyer
397adb8588SArthur O'Dwyer namespace DecltypeAuto {
407adb8588SArthur O'Dwyer int i;
f1()417adb8588SArthur O'Dwyer decltype(auto) f1() { }
f2()427adb8588SArthur O'Dwyer decltype(auto) f2() { return; }
f3()437adb8588SArthur O'Dwyer decltype(auto) f3() { return void(); }
f4()447adb8588SArthur O'Dwyer decltype(auto) f4() {
457adb8588SArthur O'Dwyer return i;
467adb8588SArthur O'Dwyer return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
477adb8588SArthur O'Dwyer }
f5()487adb8588SArthur O'Dwyer decltype(auto) f5() {
497adb8588SArthur O'Dwyer return i;
507adb8588SArthur O'Dwyer return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
517adb8588SArthur O'Dwyer }
527adb8588SArthur O'Dwyer
537adb8588SArthur O'Dwyer auto l1 = []() -> decltype(auto) { };
547adb8588SArthur O'Dwyer auto l2 = []() -> decltype(auto) { return; };
557adb8588SArthur O'Dwyer auto l3 = []() -> decltype(auto) { return void(); };
567adb8588SArthur O'Dwyer auto l4 = []() -> decltype(auto) {
577adb8588SArthur O'Dwyer return i;
587adb8588SArthur O'Dwyer return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
597adb8588SArthur O'Dwyer };
607adb8588SArthur O'Dwyer auto l5 = []() -> decltype(auto) {
617adb8588SArthur O'Dwyer return i;
627adb8588SArthur O'Dwyer return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}}
637adb8588SArthur O'Dwyer };
647adb8588SArthur O'Dwyer
657adb8588SArthur O'Dwyer } // namespace DecltypeAuto
667adb8588SArthur O'Dwyer
677adb8588SArthur O'Dwyer namespace AutoPtr {
687adb8588SArthur O'Dwyer int i;
f1()697adb8588SArthur O'Dwyer auto *f1() { } // expected-error {{cannot deduce return type 'auto *' for function with no return statements}}
f2()707adb8588SArthur O'Dwyer auto *f2() {
717adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
727adb8588SArthur O'Dwyer }
f3()737adb8588SArthur O'Dwyer auto *f3() {
747adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
757adb8588SArthur O'Dwyer }
f4()767adb8588SArthur O'Dwyer auto *f4() {
777adb8588SArthur O'Dwyer return &i;
787adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
797adb8588SArthur O'Dwyer }
f5()807adb8588SArthur O'Dwyer auto *f5() {
817adb8588SArthur O'Dwyer return &i;
827adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
837adb8588SArthur O'Dwyer }
847adb8588SArthur O'Dwyer
__anon22edc4580602() 857adb8588SArthur O'Dwyer auto l1 = []() -> auto* { }; // expected-error {{cannot deduce return type 'auto *' for function with no return statements}}
__anon22edc4580702() 867adb8588SArthur O'Dwyer auto l2 = []() -> auto* {
877adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
887adb8588SArthur O'Dwyer };
__anon22edc4580802() 897adb8588SArthur O'Dwyer auto l3 = []() -> auto* {
907adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
917adb8588SArthur O'Dwyer };
__anon22edc4580902() 927adb8588SArthur O'Dwyer auto l4 = []() -> auto* {
937adb8588SArthur O'Dwyer return &i;
947adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
957adb8588SArthur O'Dwyer };
__anon22edc4580a02() 967adb8588SArthur O'Dwyer auto l5 = []() -> auto* {
977adb8588SArthur O'Dwyer return &i;
987adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
997adb8588SArthur O'Dwyer };
1007adb8588SArthur O'Dwyer } // namespace AutoPtr
1017adb8588SArthur O'Dwyer
1027adb8588SArthur O'Dwyer namespace AutoRef {
1037adb8588SArthur O'Dwyer int i;
f1()1047adb8588SArthur O'Dwyer auto& f1() { // expected-error {{cannot deduce return type 'auto &' for function with no return statements}}
1057adb8588SArthur O'Dwyer }
f2()1067adb8588SArthur O'Dwyer auto& f2() {
1077adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
1087adb8588SArthur O'Dwyer }
f3()1097adb8588SArthur O'Dwyer auto& f3() {
1107adb8588SArthur O'Dwyer return void(); // expected-error@-1 {{cannot form a reference to 'void'}}
1117adb8588SArthur O'Dwyer }
f4()1127adb8588SArthur O'Dwyer auto& f4() {
1137adb8588SArthur O'Dwyer return i;
1147adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
1157adb8588SArthur O'Dwyer }
f5()1167adb8588SArthur O'Dwyer auto& f5() {
1177adb8588SArthur O'Dwyer return i;
118*989f76ceSMatheus Izvekov return void(); // expected-error {{deduced as 'int' in earlier return statement}}
1197adb8588SArthur O'Dwyer }
f6()1207adb8588SArthur O'Dwyer auto& f6() { return 42; } // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
1217adb8588SArthur O'Dwyer
__anon22edc4580b02() 1227adb8588SArthur O'Dwyer auto l1 = []() -> auto& { }; // expected-error {{cannot deduce return type 'auto &' for function with no return statements}}
__anon22edc4580c02() 1237adb8588SArthur O'Dwyer auto l2 = []() -> auto& {
1247adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
1257adb8588SArthur O'Dwyer };
__anon22edc4580d02() 1267adb8588SArthur O'Dwyer auto l3 = []() -> auto& { // expected-error {{cannot form a reference to 'void'}}
1277adb8588SArthur O'Dwyer return void();
1287adb8588SArthur O'Dwyer };
__anon22edc4580e02() 1297adb8588SArthur O'Dwyer auto l4 = []() -> auto& {
1307adb8588SArthur O'Dwyer return i;
1317adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
1327adb8588SArthur O'Dwyer };
__anon22edc4580f02() 133*989f76ceSMatheus Izvekov auto l5 = []() -> auto & {
1347adb8588SArthur O'Dwyer return i;
135*989f76ceSMatheus Izvekov return void(); // expected-error {{deduced as 'int' in earlier return statement}}
1367adb8588SArthur O'Dwyer };
__anon22edc4581002() 1377adb8588SArthur O'Dwyer auto l6 = []() -> auto& {
1387adb8588SArthur O'Dwyer return 42; // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
1397adb8588SArthur O'Dwyer };
1407adb8588SArthur O'Dwyer } // namespace AutoRef
141