diff mbox

[C++] PR 63265

Message ID 5462096E.9090308@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 11, 2014, 1:04 p.m. UTC
Hi,

On 11/10/2014 06:16 PM, Jason Merrill wrote:
> I don't think we want to suppress this warning in general.  The 
> problem in this PR is that the warning code is failing to recognize 
> that the first operand is constant false.
Thanks. Then, shall we do something like the below? Passes testing.

Thanks,
Paolo.

//////////////////
/cp
2014-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/63265
	* pt.c (tsubst_copy_and_build, case COND_EXPR): Maybe fold to
	const the condition.

/testsuite
2014-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/63265
	* g++.dg/cpp0x/constexpr-63265.C: New.

Comments

Jason Merrill Nov. 11, 2014, 1:19 p.m. UTC | #1
On 11/11/2014 08:04 AM, Paolo Carlini wrote:
> -	tree cond = RECUR (TREE_OPERAND (t, 0));
> +	tree cond
> +	  = maybe_constant_value (fold_non_dependent_expr_sfinae
> +				  (RECUR (TREE_OPERAND (t, 0)), tf_none));

I like this approach, but if the result of maybe_constant_value doesn't 
turn out to be an INTEGER_CST, we want to end up with the result of 
RECUR rather than the result of fold_non_dependent_expr, as the latter 
might not be suitable for subsequent tsubsting.

Jason
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 217342)
+++ cp/pt.c	(working copy)
@@ -15137,7 +15137,9 @@  tsubst_copy_and_build (tree t,
 
     case COND_EXPR:
       {
-	tree cond = RECUR (TREE_OPERAND (t, 0));
+	tree cond
+	  = maybe_constant_value (fold_non_dependent_expr_sfinae
+				  (RECUR (TREE_OPERAND (t, 0)), tf_none));
 	tree exp1, exp2;
 
 	if (TREE_CODE (cond) == INTEGER_CST)
Index: testsuite/g++.dg/cpp0x/constexpr-63265.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-63265.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-63265.C	(working copy)
@@ -0,0 +1,19 @@ 
+// PR c++/63265
+// { dg-do compile { target c++11 } }
+
+#define LSHIFT (sizeof(unsigned int) * __CHAR_BIT__)
+
+template <int lshift>
+struct SpuriouslyWarns1 {
+    static constexpr unsigned int v = lshift < LSHIFT ? 1U << lshift : 0;
+};
+
+static_assert(SpuriouslyWarns1<LSHIFT>::v == 0, "Impossible occurred");
+
+template <int lshift>
+struct SpuriouslyWarns2 {
+    static constexpr bool okay = lshift < LSHIFT;
+    static constexpr unsigned int v = okay ? 1U << lshift : 0;
+};
+
+static_assert(SpuriouslyWarns2<LSHIFT>::v == 0, "Impossible occurred");