]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/88554
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Jan 2019 08:57:58 +0000 (08:57 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Jan 2019 08:57:58 +0000 (08:57 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@267672 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wreturn-type-11.C [new file with mode: 0644]

index 4da1c82334a2a9be16c5c1659cc3c02d5c001f30..32c7f40b2129f994d7b3514a23a9410010244402 100644 (file)
@@ -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.
index 220a95c4b0ff01fa6a290d2de595e3c0b71d15e4..f456c070dcd2f361874933125a9fd5ee8b7a1acf 100644 (file)
@@ -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");
index 23de2ea6f0b08fb001b1086862cb1018c82ed81f..552ba4dd9778a3eb85bfdf3bcde455024992dc90 100644 (file)
@@ -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 (file)
index 0000000..35d05eb
--- /dev/null
@@ -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 }