This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH to fix another ICE with stray template code (PR c++/84596)


Here's another case of a template code leaking into cxx_constant_value.
While I recently added the require_rvalue_constant_expression check, it
doesn't help here, because the problem is that we have a MODOP_EXPR (a
template code), whose op1 is a TRUNC_DIV_EXPR without a type, so it's
considered dependent, so fold_non_dependent_expr doesn't do its job.

I thought we might skip calling cxx_constant_value when processing a template;
we've already given an error in any case.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-03-13  Marek Polacek  <polacek@redhat.com>

	PR c++/84596
	* semantics.c (finish_static_assert): Don't call cxx_constant_value
	when processing a template.

	* g++.dg/cpp0x/static_assert15.C: New test.

diff --git gcc/cp/semantics.c gcc/cp/semantics.c
index bb8b5953539..8680322a76c 100644
--- gcc/cp/semantics.c
+++ gcc/cp/semantics.c
@@ -8681,7 +8681,8 @@ finish_static_assert (tree condition, tree message, location_t location,
       else if (condition && condition != error_mark_node)
 	{
 	  error ("non-constant condition for static assertion");
-	  if (require_rvalue_constant_expression (condition))
+	  if (!processing_template_decl
+	      && require_rvalue_constant_expression (condition))
 	    cxx_constant_value (condition);
 	}
       input_location = saved_loc;
diff --git gcc/testsuite/g++.dg/cpp0x/static_assert15.C gcc/testsuite/g++.dg/cpp0x/static_assert15.C
index e69de29bb2d..dfb64ad5e1b 100644
--- gcc/testsuite/g++.dg/cpp0x/static_assert15.C
+++ gcc/testsuite/g++.dg/cpp0x/static_assert15.C
@@ -0,0 +1,10 @@
+// PR c++/84596
+// { dg-do compile { target c++11 } }
+
+template<int x>
+struct a {
+  constexpr void b() {
+    int c;
+    static_assert(c %= 1, ""); // { dg-error "non-constant" }
+  }
+};

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]