aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-01-08 08:57:58 +0000
committerJakub Jelinek <jakub@gcc.gnu.org>2019-01-08 09:57:58 +0100
commitff0425cdeb49db33d4bfe736829005544b45e659 (patch)
tree2543158574fdc0776e2b1b7f480d733de18aedff /gcc
parent44e813ecd1fa610e3e4ed2420a69d4a1e200b19c (diff)
downloadgcc-ff0425cdeb49db33d4bfe736829005544b45e659.zip
gcc-ff0425cdeb49db33d4bfe736829005544b45e659.tar.gz
gcc-ff0425cdeb49db33d4bfe736829005544b45e659.tar.bz2
re PR c++/88554 (Segfault ICE when falling off the end of a reference-returning friend operator)
PR c++/88554 * decl.c (finish_function): For -Wreturn-type don't add a return *this; fixit hint if current_class_ref is NULL. Use a single if instead of two nested ones. * g++.dg/warn/Wreturn-type-11.C: New test. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r267672
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/decl.c9
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/warn/Wreturn-type-11.C11
4 files changed, 30 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4da1c82..32c7f40 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2019-01-08 Jonathan Wakely <jwakely@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/88554
+ * decl.c (finish_function): For -Wreturn-type don't add a return *this;
+ fixit hint if current_class_ref is NULL. Use a single if instead of
+ two nested ones.
+
2019-01-07 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (start_decl): Improve two error_at locations.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 220a95c..f456c07 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -16097,11 +16097,12 @@ finish_function (bool inline_p)
{
tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
if (TREE_CODE (valtype) == REFERENCE_TYPE
+ && current_class_ref
&& same_type_ignoring_top_level_qualifiers_p
- (TREE_TYPE (valtype), TREE_TYPE (current_class_ref)))
- if (global_dc->option_enabled (OPT_Wreturn_type,
- global_dc->option_state))
- add_return_star_this_fixit (&richloc, fndecl);
+ (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
+ && global_dc->option_enabled (OPT_Wreturn_type,
+ global_dc->option_state))
+ add_return_star_this_fixit (&richloc, fndecl);
}
warning_at (&richloc, OPT_Wreturn_type,
"no return statement in function returning non-void");
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 23de2ea..552ba4d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-01-08 Jonathan Wakely <jwakely@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/88554
+ * g++.dg/warn/Wreturn-type-11.C: New test.
+
2019-01-07 David Malcolm <dmalcolm@redhat.com>
PR jit/88747
diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-11.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-11.C
new file mode 100644
index 0000000..35d05eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-11.C
@@ -0,0 +1,11 @@
+// PR c++/88554
+// { dg-do compile }
+// { dg-options "-Wreturn-type" }
+
+struct X {
+ friend X & operator+= (X &, int) { } // { dg-warning "no return statement in function returning non-void" }
+ // { dg-bogus "return \\*this;" "" { target *-*-* } .-1 }
+};
+struct Y {};
+Y & operator += (Y &, Y &) { } // { dg-warning "no return statement in function returning non-void" }
+ // { dg-bogus "return \\*this;" "" { target *-*-* } .-1 }