Commit 50457b9e by Paolo Carlini Committed by Paolo Carlini

re PR c++/63265 (Constexpr variables can trigger spurious compiler warnings)

/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
	constant the condition.

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

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

From-SVN: r217361
parent 3f3f5af0
2014-11-11 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63265
* pt.c (tsubst_copy_and_build, case COND_EXPR): Maybe fold to
constant the condition.
2014-11-10 Andi Kleen <ak@linux.intel.com> 2014-11-10 Andi Kleen <ak@linux.intel.com>
* semantics.c (finish_goto_stmt): Call check_no_cilk. * semantics.c (finish_goto_stmt): Call check_no_cilk.
......
...@@ -15138,11 +15138,13 @@ tsubst_copy_and_build (tree t, ...@@ -15138,11 +15138,13 @@ tsubst_copy_and_build (tree t,
case COND_EXPR: case COND_EXPR:
{ {
tree cond = RECUR (TREE_OPERAND (t, 0)); tree cond = RECUR (TREE_OPERAND (t, 0));
tree folded_cond = (maybe_constant_value
(fold_non_dependent_expr_sfinae (cond, tf_none)));
tree exp1, exp2; tree exp1, exp2;
if (TREE_CODE (cond) == INTEGER_CST) if (TREE_CODE (folded_cond) == INTEGER_CST)
{ {
if (integer_zerop (cond)) if (integer_zerop (folded_cond))
{ {
++c_inhibit_evaluation_warnings; ++c_inhibit_evaluation_warnings;
exp1 = RECUR (TREE_OPERAND (t, 1)); exp1 = RECUR (TREE_OPERAND (t, 1));
...@@ -15156,6 +15158,7 @@ tsubst_copy_and_build (tree t, ...@@ -15156,6 +15158,7 @@ tsubst_copy_and_build (tree t,
exp2 = RECUR (TREE_OPERAND (t, 2)); exp2 = RECUR (TREE_OPERAND (t, 2));
--c_inhibit_evaluation_warnings; --c_inhibit_evaluation_warnings;
} }
cond = folded_cond;
} }
else else
{ {
......
2014-11-11 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63265
* g++.dg/cpp0x/constexpr-63265.C: New.
2014-11-11 Evgeny Stupachenko <evstupac@gmail.com> 2014-11-11 Evgeny Stupachenko <evstupac@gmail.com>
* gcc.target/i386/pr52252-atom-1.c: New. * gcc.target/i386/pr52252-atom-1.c: New.
......
// 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");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment