public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Diagnose constexpr overflow (PR c++/70323)
@ 2016-03-22 21:37 Jakub Jelinek
  2016-03-23 18:57 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2016-03-22 21:37 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

On the following testcase, the first function is cp_folded into
return i == 0 ? 2147483648(OVF): 2147483647;
The problem is that we don't diagnose then the overflow at all.
We already have code that sets *overflow_p under right conditions,
just there wasn't any permerror call.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2016-03-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/70323
	* constexpr.c (cxx_eval_constant_expression): Diagnose overflow
	on TREE_OVERFLOW constants.

	* g++.dg/cpp0x/constexpr-70323.C: New test.

--- gcc/cp/constexpr.c.jj	2016-03-22 09:05:32.000000000 +0100
+++ gcc/cp/constexpr.c	2016-03-22 10:38:58.598077573 +0100
@@ -3306,8 +3306,13 @@ cxx_eval_constant_expression (const cons
     }
   if (CONSTANT_CLASS_P (t))
     {
-      if (TREE_OVERFLOW (t) && (!flag_permissive || ctx->quiet))
-	*overflow_p = true;
+      if (TREE_OVERFLOW (t))
+	{
+	  if (!ctx->quiet)
+	    permerror (input_location, "overflow in constant expression");
+	  if (!flag_permissive || ctx->quiet)
+	    *overflow_p = true;
+	}
       return t;
     }
 
--- gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C.jj	2016-03-22 10:42:54.093884158 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C	2016-03-22 10:42:29.000000000 +0100
@@ -0,0 +1,10 @@
+// PR c++/70323
+// { dg-do compile { target c++11 } }
+
+constexpr int overflow_if_0 (int i) { return __INT_MAX__ + !i; }
+constexpr int overflow_if_1 (int i) { return __INT_MAX__ + i; }
+
+constexpr bool i0_0 = overflow_if_0 (0);   // { dg-error "overflow in constant expression" }
+constexpr bool i0_1 = overflow_if_0 (1);
+constexpr bool i1_0 = overflow_if_1 (0);
+constexpr bool i1_1 = overflow_if_1 (1);   // { dg-error "overflow in constant expression" }

	Jakub

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

end of thread, other threads:[~2016-03-24 17:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-22 21:37 [C++ PATCH] Diagnose constexpr overflow (PR c++/70323) Jakub Jelinek
2016-03-23 18:57 ` Jason Merrill
2016-03-24 18:25   ` Jason Merrill

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).