public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]  Adding warning for constexpr's
@ 2015-06-12 21:35 Andres Tiraboschi
  2015-06-13  2:33 ` Joseph Myers
  0 siblings, 1 reply; 5+ messages in thread
From: Andres Tiraboschi @ 2015-06-12 21:35 UTC (permalink / raw)
  To: gcc-patches

Hi, this patch is for adding a warning when a constexpr cannot be evaluated at compile time.
This is a single case:
type var = fun(args...), with fun declared as a constexpr.

diff --git a/gcc/common.opt b/gcc/common.opt
index b49ac46..88374b1 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -581,6 +581,10 @@ Winline
 Common Var(warn_inline) Warning
 Warn when an inlined function cannot be inlined
 
+Wconstexpr
+Common Var(warn_constexpr) Warning
+Warn when a constexpr function is not evaluated at compile time
+
 Winvalid-memory-model
 Common Var(warn_invalid_memory_model) Init(1) Warning
 Warn when an atomic memory model parameter is known to be outside the valid range.
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 80a6939..e25c240 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -842,6 +842,15 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
       TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
     }
+  else if (TREE_CODE(init) == CALL_EXPR)
+    {
+      tree fn = TREE_OPERAND(CALL_EXPR_FN(init), 0);
+      if (DECL_DECLARED_CONSTEXPR_P(fn) && warn_constexpr)
+        {
+          warning (OPT_Wconstexpr, "function %q+F cannot be evaluated at compile time", fn);
+          warning (OPT_Wconstexpr, "called from here");
+        }
+    }
 
   if (cxx_dialect >= cxx14)
     /* Handle aggregate NSDMI in non-constant initializers, too.  */

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-16  0:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-12 21:35 [PATCH] Adding warning for constexpr's Andres Tiraboschi
2015-06-13  2:33 ` Joseph Myers
2015-06-15 15:12   ` Andres Tiraboschi
2015-06-15 19:58   ` Andres Tiraboschi
2015-06-16  0:39     ` Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).