141 lines · cpp
1// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s2// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s3 4// Check that we don't get any extra warning for "return" without an5// expression, in a function that might have been intended to return6// void all along.7decltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}}8 return;9}10 11namespace JustAuto {12int i;13auto f1() { }14auto f2() { return; }15auto f3() { return void(); }16auto 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}20auto 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 25auto l1 = []() { };26auto l2 = []() { return; };27auto l3 = []() { return void(); };28auto 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};32auto 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 JustAuto38 39namespace DecltypeAuto {40int i;41decltype(auto) f1() { }42decltype(auto) f2() { return; }43decltype(auto) f3() { return void(); }44decltype(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}48decltype(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 53auto l1 = []() -> decltype(auto) { };54auto l2 = []() -> decltype(auto) { return; };55auto l3 = []() -> decltype(auto) { return void(); };56auto 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};60auto 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 DecltypeAuto66 67namespace AutoPtr {68int i;69auto *f1() { } // expected-error {{cannot deduce return type 'auto *' for function with no return statements}}70auto *f2() {71 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}72}73auto *f3() {74 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}75}76auto *f4() {77 return &i;78 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}79}80auto *f5() {81 return &i;82 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}83}84 85auto l1 = []() -> auto* { }; // expected-error {{cannot deduce return type 'auto *' for function with no return statements}}86auto l2 = []() -> auto* {87 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}88};89auto l3 = []() -> auto* {90 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}91};92auto l4 = []() -> auto* {93 return &i;94 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}95};96auto l5 = []() -> auto* {97 return &i;98 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}99};100} // namespace AutoPtr101 102namespace AutoRef {103int i;104auto& f1() { // expected-error {{cannot deduce return type 'auto &' for function with no return statements}}105}106auto& f2() {107 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}108}109auto& f3() {110 return void(); // expected-error@-1 {{cannot form a reference to 'void'}}111}112auto& f4() {113 return i;114 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}115}116auto& f5() {117 return i;118 return void(); // expected-error {{deduced as 'int' in earlier return statement}}119}120auto& f6() { return 42; } // expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}121 122auto l1 = []() -> auto& { }; // expected-error {{cannot deduce return type 'auto &' for function with no return statements}}123auto l2 = []() -> auto& {124 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}125};126auto l3 = []() -> auto& { // expected-error {{cannot form a reference to 'void'}}127 return void();128};129auto l4 = []() -> auto& {130 return i;131 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}132};133auto l5 = []() -> auto & {134 return i;135 return void(); // expected-error {{deduced as 'int' in earlier return statement}}136};137auto 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 AutoRef141