This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/60379 (bogus error with loop in template)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 01 Mar 2014 15:57:25 -0500
- Subject: C++ PATCH for c++/60379 (bogus error with loop in template)
- Authentication-results: sourceware.org; auth=none
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 <jason@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)))
+ ;
+ }
+};