Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / deduced-return-void.cpp
blob84d5936c830ae2b752c08bb0d03c368d405b092f
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
6 // void all along.
7 decltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}}
8 return;
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}}
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}}
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}}
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}}
37 } // namespace JustAuto
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}}
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}}
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}}
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}}
65 } // namespace DecltypeAuto
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}}
73 auto *f3() {
74 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
76 auto *f4() {
77 return &i;
78 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
80 auto *f5() {
81 return &i;
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* {
93 return &i;
94 return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
96 auto l5 = []() -> auto* {
97 return &i;
98 return void(); // expected-error {{cannot deduce return type 'auto *' from returned value of type 'void'}}
100 } // namespace AutoPtr
102 namespace AutoRef {
103 int i;
104 auto& f1() { // expected-error {{cannot deduce return type 'auto &' for function with no return statements}}
106 auto& f2() {
107 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
109 auto& f3() {
110 return void(); // expected-error@-1 {{cannot form a reference to 'void'}}
112 auto& f4() {
113 return i;
114 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
116 auto& f5() {
117 return i;
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'}}
127 return void();
129 auto l4 = []() -> auto& {
130 return i;
131 return; // expected-error {{cannot deduce return type 'auto &' from omitted return expression}}
133 auto l5 = []() -> auto & {
134 return i;
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