We shouldn't complain if a loop condition isn't a valid constant
expression; it isn't supposed to be.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 5266ff07b6077df5d7bf6d5748856a43e48ad6ee
Author: Jason Merrill <ja...@redhat.com>
Date: Sat Mar 1 14:22:02 2014 -0500
PR c++/60379
* semantics.c (begin_maybe_infinite_loop): Use
fold_non_dependent_expr_sfinae.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 9c1c29d..eaeeb24 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -503,7 +503,7 @@ begin_maybe_infinite_loop (tree cond)
bool maybe_infinite = true;
if (cond)
{
- cond = fold_non_dependent_expr (cond);
+ cond = fold_non_dependent_expr_sfinae (cond, tf_none);
cond = maybe_constant_value (cond);
maybe_infinite = integer_nonzerop (cond);
}
diff --git a/gcc/testsuite/g++.dg/template/loop1.C b/gcc/testsuite/g++.dg/template/loop1.C
new file mode 100644
index 0000000..aa6d177
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/loop1.C
@@ -0,0 +1,9 @@
+// PR c++/60379
+
+template <int> struct A {
+ void m_fn1(int p1) {
+ int *a;
+ while (p1 && *static_cast<int *>(static_cast<void *>(a)))
+ ;
+ }
+};