[Bug c++/96182] GCC accepts constexpr function with no return-statement

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jul 13 12:36:13 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96182

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So we could do something like:
--- gcc/cp/decl.c.jj    2020-07-09 11:27:51.088908783 +0200
+++ gcc/cp/decl.c       2020-07-13 14:34:59.887259561 +0200
@@ -17164,7 +17164,9 @@ finish_function (bool inline_p)
   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;

   /* Complain if there's just no return statement.  */
-  if (warn_return_type
+  if ((warn_return_type
+       || (cxx_dialect >= cxx14
+          && DECL_DECLARED_CONSTEXPR_P (fndecl)))
       && !VOID_TYPE_P (TREE_TYPE (fntype))
       && !dependent_type_p (TREE_TYPE (fntype))
       && !current_function_returns_value && !current_function_returns_null
@@ -17196,8 +17198,12 @@ finish_function (bool inline_p)
                                            global_dc->option_state))
            add_return_star_this_fixit (&richloc, fndecl);
        }
-      if (warning_at (&richloc, OPT_Wreturn_type,
-         "no return statement in function returning non-void"))
+      if (cxx_dialect >= cxx14 && DECL_DECLARED_CONSTEXPR_P (fndecl))
+       error_at (&richloc, "no return statement in %<constexpr%> function "
+                           "returning non-void");
+      else if (warning_at (&richloc, OPT_Wreturn_type,
+                          "no return statement in function returning "
+                          "non-void"))
        TREE_NO_WARNING (fndecl) = 1;
     }

and look for what breaks.


More information about the Gcc-bugs mailing list