@@ -11192,7 +11192,9 @@ c_finish_return (location_t loc, tree retval, tree origtype)
&& valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
{
no_warning = true;
- if (emit_diagnostic (flag_isoc99 ? DK_PEDWARN : DK_WARNING,
+ if (emit_diagnostic (flag_isoc99 && !flag_pedantic_errors
+ ? DK_PERMERROR
+ : flag_isoc99 ? DK_PEDWARN : DK_WARNING,
loc, OPT_Wreturn_mismatch,
"%<return%> with no value,"
" in function returning non-void"))
@@ -11205,7 +11207,7 @@ c_finish_return (location_t loc, tree retval, tree origtype)
current_function_returns_null = 1;
bool warned_here;
if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
- warned_here = pedwarn
+ warned_here = pedpermerror
(xloc, OPT_Wreturn_mismatch,
"%<return%> with a value, in function returning void");
else
@@ -6183,6 +6183,7 @@ that have their own flag:
-Wimplicit-int @r{(C)}
-Wint-conversion @r{(C)}
-Wnarrowing @r{(C++)}
+-Wreturn-mismatch @r{(C)}
}
The @option{-fpermissive} option is the default for historic C language
@@ -7373,7 +7374,10 @@ Attempting to use the return value of a non-@code{void} function other
than @code{main} that flows off the end by reaching the closing curly
brace that terminates the function is undefined.
-This warning is specific to C and enabled by default.
+This warning is specific to C and enabled by default. In C99 and later
+language dialects, it is treated as an error. It an be downgraded
+to a warning using @option{-fpermissive} (along with other warnings),
+or for just this warning, with @option{-Wno-error=return-mismatch}.
@opindex Wreturn-type
@opindex Wno-return-type
@@ -2,7 +2,7 @@
Copyright (C) 2003 Free Software Foundation Inc. */
/* { dg-do compile } */
-/* { dg-options "-O -finline-functions -Wreturn-type" } */
+/* { dg-options "-fpermissive -O -finline-functions -Wreturn-type" } */
extern int i;
extern int foo (void);
new file mode 100644
@@ -0,0 +1,21 @@
+/* Bug 9862 -- Spurious warnings with -finline-functions.
+ Copyright (C) 2003 Free Software Foundation Inc. */
+
+/* { dg-do compile } */
+/* { dg-options "-O -finline-functions -Wreturn-type" } */
+
+extern int i;
+extern int foo (void);
+extern int bar (void);
+
+int foo (void)
+{
+ if( i ) return 0;
+ else return 1;
+}
+
+int bar (void)
+{
+ if( i ) return; /* { dg-error "'return' with no value, in function returning non-void" } */
+ else return 1;
+}
@@ -2,7 +2,7 @@
Copyright (C) 2003 Free Software Foundation Inc. */
/* { dg-do compile } */
-/* { dg-options "-O -finline-functions -Wreturn-type" } */
+/* { dg-options "-fpermissive -O -finline-functions -Wreturn-type" } */
extern int i;
extern int foo (void);
new file mode 100644
@@ -0,0 +1,21 @@
+/* Bug 9862 -- Spurious warnings with -finline-functions.
+ Copyright (C) 2003 Free Software Foundation Inc. */
+
+/* { dg-do compile } */
+/* { dg-options "-O -finline-functions -Wreturn-type" } */
+
+extern int i;
+extern int foo (void);
+extern int bar (void);
+
+int foo (void)
+{
+ if( i ) return; /* { dg-error "'return' with no value, in function returning non-void" } */
+ else return 1;
+}
+
+int bar (void)
+{
+ if( i ) return 0;
+ else return 1;
+}
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-fpermissive" } */
void f1 (void);
new file mode 100644
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void f1 (void);
+
+int
+f2 (void)
+{
+ f1 ();
+}
+
+static inline int
+f3 (void)
+{
+ f1 ();
+}
+
+void
+f4 (void)
+{
+ return 1; /* { dg-error "'return' with a value\[^\n\r\]*-Wreturn-mismatch" } */
+}
+
+void
+f5 (void)
+{
+ return f1 (); /* { dg-bogus "ISO C" } */
+}
+
+int
+f6 (void)
+{
+ return; /* { dg-error "'return' with no value\[^\n\r\]*-Wreturn-mismatch" } */
+}
+
+int
+f7 (void)
+{
+ return f1 (); /* { dg-error "void value not ignored as it ought to be" } */
+}
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-Wall" } */
+/* { dg-options "-fpermissive -Wall" } */
void f1 (void);
new file mode 100644
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+void f1 (void);
+
+int
+f2 (void)
+{
+ f1 ();
+} /* { dg-warning "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */
+
+static inline int
+f3 (void)
+{
+ f1 ();
+} /* { dg-warning "no return statement in function\[^\n\r\]*-Wreturn-type" } */
+
+void
+f4 (void)
+{
+ return 1; /* { dg-error "with a value,\[^\n\r\]*-Wreturn-mismatch" } */
+}
+
+void
+f5 (void)
+{
+ return f1 ();
+}
+
+int
+f6 (void)
+{
+ return; /* { dg-error "with no value,\[^\n\r\]*Wreturn-mismatch" } */
+}
+
+int
+f7 (void)
+{
+ return f1 (); /* { dg-error "void value not ignored as it ought to be" } */
+} /* { dg-warning "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */
+
new file mode 100644
@@ -0,0 +1,52 @@
+/* { dg-options "-fdiagnostics-show-caret -Wreturn-local-addr" } */
+
+int *address_of_local (void)
+{
+ int some_local;
+ return &some_local; /* { dg-warning "function returns address of local variable" } */
+/* { dg-begin-multiline-output "" }
+ return &some_local;
+ ^~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+}
+
+void surplus_return_when_void_1 (void)
+{
+ return 500; /* { dg-error "'return' with a value, in function returning void" } */
+/* { dg-begin-multiline-output "" }
+ return 500;
+ ^~~
+ { dg-end-multiline-output "" } */
+/* { dg-begin-multiline-output "" }
+ void surplus_return_when_void_1 (void)
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+}
+
+void surplus_return_when_void_2 (int i, int j)
+{
+ return i * j; /* { dg-error "'return' with a value, in function returning void" } */
+/* { dg-begin-multiline-output "" }
+ return i * j;
+ ~~^~~
+ { dg-end-multiline-output "" } */
+/* { dg-begin-multiline-output "" }
+ void surplus_return_when_void_2 (int i, int j)
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+}
+
+int missing_return_value (void)
+{
+ return; /* { dg-error "'return' with no value, in function returning non-void" } */
+/* { dg-begin-multiline-output "" }
+ return;
+ ^~~~~~
+ { dg-end-multiline-output "" } */
+/* { dg-begin-multiline-output "" }
+ int missing_return_value (void)
+ ^~~~~~~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+/* TODO: ideally we'd underline the return type i.e. "int", but that
+ location isn't captured. */
+}
@@ -1,4 +1,4 @@
-/* { dg-options "-fdiagnostics-show-caret -Wreturn-local-addr" } */
+/* { dg-options "-fpermissive -fdiagnostics-show-caret -Wreturn-local-addr" } */
int *address_of_local (void)
{
@@ -7,5 +7,5 @@ void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type
foo (int x, int y) /* { dg-error "return type defaults to 'int'" } */
{ /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */
/* { dg-message "declared here" "" { target *-*-* } .-2 } */
- return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */
+ return (x >= 0) != (y < 0); /* { dg-error "'return' with a value, in function returning void" } */
}
new file mode 100644
@@ -0,0 +1,14 @@
+/* PR c/23075 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wreturn-type" } */
+
+int
+foo (void)
+{
+ return; /* { dg-error "with no value" } */
+} /* { dg-bogus "control reaches end" } */
+
+int
+bar (void)
+{
+} /* { dg-warning "control reaches end" } */
@@ -1,6 +1,6 @@
/* PR c/23075 */
/* { dg-do compile } */
-/* { dg-options "-O2 -Wreturn-type" } */
+/* { dg-options "-O2 -fpermissive -Wreturn-type" } */
int
foo (void)
new file mode 100644
@@ -0,0 +1,15 @@
+/* PR 29521 : warning for return with expression in function returning void */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void func (void) { }
+
+void func2 (void)
+{
+ return func ();
+}
+
+void func3 (void)
+{
+ return 1; /* { dg-error "'return' with a value" } */
+}
@@ -1,6 +1,6 @@
/* PR 29521 : warning for return with expression in function returning void */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-fpermissive" } */
void func (void) { }
new file mode 100644
@@ -0,0 +1,11 @@
+/* PR c/67730 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+#include <stddef.h>
+
+void
+fn1 (void)
+{
+ return NULL; /* { dg-error "10:.return. with a value" } */
+}
@@ -1,6 +1,6 @@
/* PR c/67730 */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-fpermissive" } */
#include <stddef.h>
@@ -1,7 +1,7 @@
/* Check that a conditional return is used. */
/* { dg-do compile } */
-/* { dg-options "-O2 -w" } */
+/* { dg-options "-O2 -fpermissive -w" } */
/* { dg-final { scan-assembler {\mbeqlr\M} } } */