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 for c++/69688 (bogus error with -Wsign-compare)


This issue is similar to c++/68586 -- maybe_constant_value returned stale
value for a decl from the cache.  Fixed by clearing the caches when we
store init value for a decl.

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

2016-02-05  Marek Polacek  <polacek@redhat.com>

	PR c++/69688
	* typeck2.c (store_init_value): Clear cv and fold caches.

	* g++.dg/init/const12.C: New test.

diff --git gcc/cp/typeck2.c gcc/cp/typeck2.c
index 419faa2..737dfe4 100644
--- gcc/cp/typeck2.c
+++ gcc/cp/typeck2.c
@@ -783,6 +783,10 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
   if (TREE_CODE (type) == ERROR_MARK)
     return NULL_TREE;
 
+  /* Here, DECL may change value; purge caches.  */
+  clear_fold_cache ();
+  clear_cv_cache ();
+
   if (MAYBE_CLASS_TYPE_P (type))
     {
       if (TREE_CODE (init) == TREE_LIST)
diff --git gcc/testsuite/g++.dg/init/const12.C gcc/testsuite/g++.dg/init/const12.C
index e69de29..2f6f9b2 100644
--- gcc/testsuite/g++.dg/init/const12.C
+++ gcc/testsuite/g++.dg/init/const12.C
@@ -0,0 +1,20 @@
+// PR c++/69688
+// { dg-do compile }
+// { dg-options "-Wsign-compare" }
+
+struct S
+{
+  static const int s;
+  static const char c[];
+  static wchar_t w[];
+
+  S ()
+    {
+      for (int i = 0; i < s; i++)
+	w[i] = 0;
+    }
+};
+
+const char S::c[] = "x";
+const int S::s = sizeof (S::c) - 1;
+wchar_t S::w[S::s];

	Marek


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