aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorVolker Reichelt <v.reichelt@netcologne.de>2017-05-25 17:05:07 +0000
committerVolker Reichelt <reichelt@gcc.gnu.org>2017-05-25 17:05:07 +0000
commit63dbcd13e93578e21e0717d4990c1701d6957e3e (patch)
tree33570c2d557c1068f7b7f286e8a8d7adf1becc24 /gcc/cp
parent932f48ac85f5111b1f3666b2c15718db2d10bcbf (diff)
downloadgcc-63dbcd13e93578e21e0717d4990c1701d6957e3e.zip
gcc-63dbcd13e93578e21e0717d4990c1701d6957e3e.tar.gz
gcc-63dbcd13e93578e21e0717d4990c1701d6957e3e.tar.bz2
invoke.texi (-Wcatch-value=): Document new warning option.
* doc/invoke.texi (-Wcatch-value=): Document new warning option. * c.opt (Wcatch-value=): New C++ warning flag. * semantics.c (finish_handler_parms): Warn about non-reference * type catch handlers. * g++.dg/warn/Wcatch-value-1.C: New test. * g++.dg/warn/Wcatch-value-2.C: New test. * g++.dg/warn/Wcatch-value-3.C: New test. From-SVN: r248466
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/semantics.c23
2 files changed, 27 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f2df2b6..6d71bd6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-25 Volker Reichelt <v.reichelt@netcologne.de>
+
+ * semantics.c (finish_handler_parms): Warn about non-reference type
+ catch handlers.
+
2017-05-25 Nathan Sidwell <nathan@acm.org>
Reimplement unqualified namespace lookup.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 1ba961e..df83d23 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1323,7 +1323,28 @@ finish_handler_parms (tree decl, tree handler)
}
}
else
- type = expand_start_catch_block (decl);
+ {
+ type = expand_start_catch_block (decl);
+ if (warn_catch_value
+ && type != NULL_TREE
+ && type != error_mark_node
+ && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE)
+ {
+ tree orig_type = TREE_TYPE (decl);
+ if (CLASS_TYPE_P (orig_type))
+ {
+ if (TYPE_POLYMORPHIC_P (orig_type))
+ warning (OPT_Wcatch_value_,
+ "catching polymorphic type %q#T by value", orig_type);
+ else if (warn_catch_value > 1)
+ warning (OPT_Wcatch_value_,
+ "catching type %q#T by value", orig_type);
+ }
+ else if (warn_catch_value > 2)
+ warning (OPT_Wcatch_value_,
+ "catching non-reference type %q#T", orig_type);
+ }
+ }
HANDLER_TYPE (handler) = type;
}