[clang] Add new flag -Wreturn-mismatch (PR #82872)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 5 06:23:14 PST 2024


================
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s
+
+// Test that -Wreturn-mismatch is enabled and -Wreturn-type is disabled.
+
+int foo(void) __attribute__((noreturn));
+int bar(void);
+
+void test1() {
+  return 1; // expected-warning{{void function 'test1' should not return a value}}
+}
+
+int test2() { 
+    return; // expected-warning{{non-void function 'test2' should return a value}}
+} 
+
+int test3() { 
+    // no-warning
----------------
AaronBallman wrote:

When you add the other RUN line, you'll use `// return-type-warning at +1 {{non-void function does not return a value}}` (similar for the other return-type.c warnings that will show up in this file).

https://github.com/llvm/llvm-project/pull/82872


More information about the cfe-commits mailing list