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'Dwyerdecltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}} 83c8d2aa8SArthur O'Dwyer return; 93c8d2aa8SArthur O'Dwyer } 10*7adb8588SArthur O'Dwyer 11*7adb8588SArthur O'Dwyer namespace JustAuto { 12*7adb8588SArthur O'Dwyer int i; f1()13*7adb8588SArthur O'Dwyerauto f1() { } f2()14*7adb8588SArthur O'Dwyerauto f2() { return; } f3()15*7adb8588SArthur O'Dwyerauto f3() { return void(); } f4()16*7adb8588SArthur O'Dwyerauto f4() { 17*7adb8588SArthur O'Dwyer return i; 18*7adb8588SArthur O'Dwyer return; // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} 19*7adb8588SArthur O'Dwyer } f5()20*7adb8588SArthur O'Dwyerauto f5() { 21*7adb8588SArthur O'Dwyer return i; 22*7adb8588SArthur O'Dwyer return void(); // expected-error {{'auto' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} 23*7adb8588SArthur O'Dwyer } 24*7adb8588SArthur O'Dwyer __anon3acab0750102() 25*7adb8588SArthur O'Dwyerauto l1 = []() { }; __anon3acab0750202() 26*7adb8588SArthur O'Dwyerauto l2 = []() { return; }; __anon3acab0750302() 27*7adb8588SArthur O'Dwyerauto l3 = []() { return void(); }; __anon3acab0750402() 28*7adb8588SArthur O'Dwyerauto l4 = []() { 29*7adb8588SArthur O'Dwyer return i; 30*7adb8588SArthur O'Dwyer return; // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}} 31*7adb8588SArthur O'Dwyer }; __anon3acab0750502() 32*7adb8588SArthur O'Dwyerauto l5 = []() { 33*7adb8588SArthur O'Dwyer return i; 34*7adb8588SArthur O'Dwyer return void(); // expected-error {{return type 'void' must match previous return type 'int' when lambda expression has unspecified explicit return type}} 35*7adb8588SArthur O'Dwyer }; 36*7adb8588SArthur O'Dwyer 37*7adb8588SArthur O'Dwyer } // namespace JustAuto 38*7adb8588SArthur O'Dwyer 39*7adb8588SArthur O'Dwyer namespace DecltypeAuto { 40*7adb8588SArthur O'Dwyer int i; f1()41*7adb8588SArthur O'Dwyerdecltype(auto) f1() { } f2()42*7adb8588SArthur O'Dwyerdecltype(auto) f2() { return; } f3()43*7adb8588SArthur O'Dwyerdecltype(auto) f3() { return void(); } f4()44*7adb8588SArthur O'Dwyerdecltype(auto) f4() { 45*7adb8588SArthur O'Dwyer return i; 46*7adb8588SArthur O'Dwyer return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} 47*7adb8588SArthur O'Dwyer } f5()48*7adb8588SArthur O'Dwyerdecltype(auto) f5() { 49*7adb8588SArthur O'Dwyer return i; 50*7adb8588SArthur O'Dwyer return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} 51*7adb8588SArthur O'Dwyer } 52*7adb8588SArthur O'Dwyer 53*7adb8588SArthur O'Dwyer auto l1 = []() -> decltype(auto) { }; 54*7adb8588SArthur O'Dwyer auto l2 = []() -> decltype(auto) { return; }; 55*7adb8588SArthur O'Dwyer auto l3 = []() -> decltype(auto) { return void(); }; 56*7adb8588SArthur O'Dwyer auto l4 = []() -> decltype(auto) { 57*7adb8588SArthur O'Dwyer return i; 58*7adb8588SArthur O'Dwyer return; // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} 59*7adb8588SArthur O'Dwyer }; 60*7adb8588SArthur O'Dwyer auto l5 = []() -> decltype(auto) { 61*7adb8588SArthur O'Dwyer return i; 62*7adb8588SArthur O'Dwyer return void(); // expected-error {{'decltype(auto)' in return type deduced as 'void' here but deduced as 'int' in earlier return statement}} 63*7adb8588SArthur O'Dwyer }; 64*7adb8588SArthur O'Dwyer 65*7adb8588SArthur O'Dwyer } // namespace DecltypeAuto 66*7adb8588SArthur O'Dwyer 67*7adb8588SArthur O'Dwyer namespace AutoPtr { 68*7adb8588SArthur O'Dwyer int i; f1()69*7adb8588SArthur O'Dwyerauto *f1() { } // expected-error {{cannot deduce return type 'auto *' for function with no return statements}} f2()70*7adb8588SArthur O'Dwyerauto *f2() { 71*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} 72*7adb8588SArthur O'Dwyer } f3()73*7adb8588SArthur O'Dwyerauto *f3() { 74*7adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} 75*7adb8588SArthur O'Dwyer } f4()76*7adb8588SArthur O'Dwyerauto *f4() { 77*7adb8588SArthur O'Dwyer return &i; 78*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} 79*7adb8588SArthur O'Dwyer } f5()80*7adb8588SArthur O'Dwyerauto *f5() { 81*7adb8588SArthur O'Dwyer return &i; 82*7adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} 83*7adb8588SArthur O'Dwyer } 84*7adb8588SArthur O'Dwyer __anon3acab0750602() 85*7adb8588SArthur O'Dwyerauto l1 = []() -> auto* { }; // expected-error {{cannot deduce return type 'auto *' for function with no return statements}} __anon3acab0750702() 86*7adb8588SArthur O'Dwyerauto l2 = []() -> auto* { 87*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} 88*7adb8588SArthur O'Dwyer }; __anon3acab0750802() 89*7adb8588SArthur O'Dwyerauto l3 = []() -> auto* { 90*7adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} 91*7adb8588SArthur O'Dwyer }; __anon3acab0750902() 92*7adb8588SArthur O'Dwyerauto l4 = []() -> auto* { 93*7adb8588SArthur O'Dwyer return &i; 94*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}} 95*7adb8588SArthur O'Dwyer }; __anon3acab0750a02() 96*7adb8588SArthur O'Dwyerauto l5 = []() -> auto* { 97*7adb8588SArthur O'Dwyer return &i; 98*7adb8588SArthur O'Dwyer return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}} 99*7adb8588SArthur O'Dwyer }; 100*7adb8588SArthur O'Dwyer } // namespace AutoPtr 101*7adb8588SArthur O'Dwyer 102*7adb8588SArthur O'Dwyer namespace AutoRef { 103*7adb8588SArthur O'Dwyer int i; f1()104*7adb8588SArthur O'Dwyerauto& f1() { // expected-error {{cannot deduce return type 'auto &' for function with no return statements}} 105*7adb8588SArthur O'Dwyer } f2()106*7adb8588SArthur O'Dwyerauto& f2() { 107*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} 108*7adb8588SArthur O'Dwyer } f3()109*7adb8588SArthur O'Dwyerauto& f3() { 110*7adb8588SArthur O'Dwyer return void(); // expected-error@-1 {{cannot form a reference to 'void'}} 111*7adb8588SArthur O'Dwyer } f4()112*7adb8588SArthur O'Dwyerauto& f4() { 113*7adb8588SArthur O'Dwyer return i; 114*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} 115*7adb8588SArthur O'Dwyer } f5()116*7adb8588SArthur O'Dwyerauto& f5() { 117*7adb8588SArthur O'Dwyer return i; 118*7adb8588SArthur O'Dwyer return void(); // expected-error@-2 {{cannot form a reference to 'void'}} 119*7adb8588SArthur O'Dwyer } f6()120*7adb8588SArthur O'Dwyerauto& f6() { return 42; } // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} 121*7adb8588SArthur O'Dwyer __anon3acab0750b02() 122*7adb8588SArthur O'Dwyerauto l1 = []() -> auto& { }; // expected-error {{cannot deduce return type 'auto &' for function with no return statements}} __anon3acab0750c02() 123*7adb8588SArthur O'Dwyerauto l2 = []() -> auto& { 124*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} 125*7adb8588SArthur O'Dwyer }; __anon3acab0750d02() 126*7adb8588SArthur O'Dwyerauto l3 = []() -> auto& { // expected-error {{cannot form a reference to 'void'}} 127*7adb8588SArthur O'Dwyer return void(); 128*7adb8588SArthur O'Dwyer }; __anon3acab0750e02() 129*7adb8588SArthur O'Dwyerauto l4 = []() -> auto& { 130*7adb8588SArthur O'Dwyer return i; 131*7adb8588SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}} 132*7adb8588SArthur O'Dwyer }; __anon3acab0750f02() 133*7adb8588SArthur O'Dwyerauto l5 = []() -> auto& { // expected-error {{cannot form a reference to 'void'}} 134*7adb8588SArthur O'Dwyer return i; 135*7adb8588SArthur O'Dwyer return void(); 136*7adb8588SArthur O'Dwyer }; __anon3acab0751002() 137*7adb8588SArthur O'Dwyerauto l6 = []() -> auto& { 138*7adb8588SArthur O'Dwyer return 42; // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} 139*7adb8588SArthur O'Dwyer }; 140*7adb8588SArthur O'Dwyer } // namespace AutoRef 141