Skip to content

Commit 8467457

Browse files
authored
Add new flag -Wreturn-mismatch (#82872)
This pull request fixes #72116 where a new flag is introduced for compatibility with GCC 14, the functionality of -Wreturn-type is modified to split some of its behaviors into -Wreturn-mismatch Fixes #72116
1 parent 866ac9a commit 8467457

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ Deprecated Compiler Flags
183183

184184
Modified Compiler Flags
185185
-----------------------
186+
- Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
187+
``-Wreturn-type``, and moved some of the diagnostics previously controlled by
188+
``-Wreturn-type`` under this new flag. Fixes #GH72116.
186189

187190
Removed Compiler Flags
188191
-------------------------

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ def GNURedeclaredEnum : DiagGroup<"gnu-redeclared-enum">;
617617
def RedundantMove : DiagGroup<"redundant-move">;
618618
def Register : DiagGroup<"register", [DeprecatedRegister]>;
619619
def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">;
620-
def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>;
620+
def ReturnMismatch : DiagGroup<"return-mismatch">;
621+
def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage, ReturnMismatch]>;
622+
621623
def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy",
622624
[CXX98CompatBindToTemporaryCopy]>;
623625
def SelfAssignmentField : DiagGroup<"self-assign-field">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10248,14 +10248,14 @@ def warn_second_parameter_to_va_arg_never_compatible : Warning<
1024810248

1024910249
def warn_return_missing_expr : Warning<
1025010250
"non-void %select{function|method}1 %0 should return a value">, DefaultError,
10251-
InGroup<ReturnType>;
10251+
InGroup<ReturnMismatch>;
1025210252
def ext_return_missing_expr : ExtWarn<
1025310253
"non-void %select{function|method}1 %0 should return a value">, DefaultError,
10254-
InGroup<ReturnType>;
10254+
InGroup<ReturnMismatch>;
1025510255
def ext_return_has_expr : ExtWarn<
1025610256
"%select{void function|void method|constructor|destructor}1 %0 "
1025710257
"should not return a value">,
10258-
DefaultError, InGroup<ReturnType>;
10258+
DefaultError, InGroup<ReturnMismatch>;
1025910259
def ext_return_has_void_expr : Extension<
1026010260
"void %select{function|method|block}1 %0 should not return void expression">;
1026110261
def err_return_init_list : Error<

clang/test/Misc/warning-wall.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CHECK-NEXT: -Wreorder-ctor
4444
CHECK-NEXT: -Wreorder-init-list
4545
CHECK-NEXT: -Wreturn-type
4646
CHECK-NEXT: -Wreturn-type-c-linkage
47+
CHECK-NEXT: -Wreturn-mismatch
4748
CHECK-NEXT: -Wself-assign
4849
CHECK-NEXT: -Wself-assign-overloaded
4950
CHECK-NEXT: -Wself-assign-field
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 -Wreturn-type -Wno-return-mismatch -fsyntax-only -verify=return-type %s
2+
// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify=return-mismatch %s
3+
4+
int foo(void) __attribute__((noreturn));
5+
int bar(void);
6+
7+
void test1(void) {
8+
return 1; // return-mismatch-warning{{void function 'test1' should not return a value}}
9+
}
10+
11+
int test2(void) {
12+
return; // return-mismatch-warning{{non-void function 'test2' should return a value}}
13+
}
14+
15+
int test3(void) {
16+
// return-type-warning@+1 {{non-void function does not return a value}}
17+
}
18+
19+
int test4(void) {
20+
(void)(bar() || foo()); // return-type-warning@+1 {{non-void function does not return a value in all control paths}}
21+
}
22+
23+
void test5(void) {
24+
} // no-warning
25+
26+
int test6(void) {
27+
return 0; // no-warning
28+
}
29+
30+
int test7(void) {
31+
foo(); // no warning
32+
}
33+
34+
int test8(void) {
35+
bar(); // return-type-warning@+1 {{non-void function does not return a value}}
36+
}

0 commit comments

Comments
 (0)