This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR c++/40749: g++ doesnt report missing return if return is of type const <type>
- From: Simon Martin <simartin at users dot sourceforge dot net>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: dmueller at suse dot de
- Date: Sat, 18 Jul 2009 00:02:15 +0200
- Subject: [PATCH] Fix PR c++/40749: g++ doesnt report missing return if return is of type const <type>
Hi,
When compiled with -Wreturn-type, the missing returns in the following
snippet is not reported starting with 4.3
=== cut ===
struct A {};
const A a() {}
const int b() {}
=== cut ===
This is due to the fix for PR#18313, that sets TREE_NO_WARNING on any
function with a qualified return type. The attached patch does not do
it, which solves the PR (the test suite does not contain any test that
proves that setting TREE_NO_WARNING was necessary...)
I have successfully regtested this on x86_64-apple-darwin-9. Is it OK
for trunk? for 4.4 and 4.3?
Best regards,
Simon
:ADDPATCH c++:
2009-07-17 Simon Martin <simartin@users.sourceforge.net>
PR c++/40749
* decl.c (grokdeclarator): Do not set TREE_NO_WARNING for functions
with a qualified return type.
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 149752)
+++ gcc/cp/decl.c (working copy)
@@ -7639,7 +7639,6 @@
bool unsigned_p, signed_p, short_p, long_p, thread_p;
bool type_was_error_mark_node = false;
bool parameter_pack_p = declarator? declarator->parameter_pack_p : false;
- bool set_no_warning = false;
bool template_type_arg = false;
const char *errmsg;
@@ -8319,7 +8318,6 @@
/* We now know that the TYPE_QUALS don't apply to the
decl, but to its return type. */
type_quals = TYPE_UNQUALIFIED;
- set_no_warning = true;
}
errmsg = targetm.invalid_return_type (type);
if (errmsg)
@@ -9541,9 +9539,6 @@
if (!processing_template_decl)
cp_apply_type_quals_to_decl (type_quals, decl);
- if (set_no_warning)
- TREE_NO_WARNING (decl) = 1;
-
return decl;
}
}
2007-07-17 Simon Martin <simartin@users.sourceforge.net>
PR c++/40749
* g++.dg/warn/Wreturn-type-6.C: New test.
/* PR c++/40749 */
/* { dg-do "compile" } */
/* { dg-options "-Wreturn-type" } */
struct A {};
const A a() {} /* { dg-warning "no return statement" } */
const A& b() {} /* { dg-warning "no return statement" } */
const int c() {} /* { dg-warning "no return statement" } */