aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2016-02-08 15:40:33 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2016-02-08 15:40:33 +0000
commiteba9e839de0a585e55a92b4815e78a781ce32abb (patch)
treee362aee6c662fd0043e5bdca1a8c68c79dad4c73
parent2158532f314617f555389157fb46b86c5ef935b3 (diff)
downloadgcc-eba9e839de0a585e55a92b4815e78a781ce32abb.zip
gcc-eba9e839de0a585e55a92b4815e78a781ce32abb.tar.gz
gcc-eba9e839de0a585e55a92b4815e78a781ce32abb.tar.bz2
re PR c++/69688 (-Wsign-compare causes bogus error: size of array ‘uc_code’ is not an integral constant-expression)
PR c++/69688 * constexpr.c (clear_cv_and_fold_caches): Renamed from clear_cv_cache. Call clear_fold_cache. * cp-tree.h: Adjust declaration. * decl.c (finish_enum_value_list): Call clear_cv_and_fold_caches rather than clear_cv_cache and clear_fold_cache. * typeck2.c (store_init_value): Call clear_cv_and_fold_caches. * g++.dg/init/const12.C: New test. From-SVN: r233220
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/constexpr.c5
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/decl.c3
-rw-r--r--gcc/cp/typeck2.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/init/const12.C20
7 files changed, 43 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 470d825..32fbe6f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+2016-02-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/69688
+ * constexpr.c (clear_cv_and_fold_caches): Renamed from clear_cv_cache.
+ Call clear_fold_cache.
+ * cp-tree.h: Adjust declaration.
+ * decl.c (finish_enum_value_list): Call clear_cv_and_fold_caches
+ rather than clear_cv_cache and clear_fold_cache.
+ * typeck2.c (store_init_value): Call clear_cv_and_fold_caches.
+
2016-02-08 Jason Merrill <jason@redhat.com>
* cp-tree.h (CONV_FOLD, CONV_BACKEND_CONVERT): New.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 05f6843..85fc64e 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4098,12 +4098,13 @@ maybe_constant_value (tree t, tree decl)
return ret;
}
-/* Dispose of the whole CV_CACHE. */
+/* Dispose of the whole CV_CACHE and FOLD_CACHE. */
void
-clear_cv_cache (void)
+clear_cv_and_fold_caches (void)
{
gt_cleare_cache (cv_cache);
+ clear_fold_cache ();
}
/* Like maybe_constant_value but first fully instantiate the argument.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 786927b..ead017e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6922,7 +6922,7 @@ extern bool var_in_constexpr_fn (tree);
extern void explain_invalid_constexpr_fn (tree);
extern vec<tree> cx_error_context (void);
extern tree fold_sizeof_expr (tree);
-extern void clear_cv_cache (void);
+extern void clear_cv_and_fold_caches (void);
/* In c-family/cilk.c */
extern bool cilk_valid_spawn (tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 2c337bc..11f7ce6 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13414,8 +13414,7 @@ finish_enum_value_list (tree enumtype)
/* Each enumerator now has the type of its enumeration. Clear the cache
so that this change in types doesn't confuse us later on. */
- clear_cv_cache ();
- clear_fold_cache ();
+ clear_cv_and_fold_caches ();
}
/* Finishes the enum type. This is called only the first time an
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 419faa2..2a76c96 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -837,6 +837,9 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
/* Handle aggregate NSDMI in non-constant initializers, too. */
value = replace_placeholders (value, decl);
+ /* DECL may change value; purge caches. */
+ clear_cv_and_fold_caches ();
+
/* If the initializer is not a constant, fill in DECL_INITIAL with
the bits that are constant, and then return an expression that
will perform the dynamic initialization. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index be3f5ec..b30f01d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/69688
+ * g++.dg/init/const12.C: New test.
+
2016-02-08 Bernd Schmidt <bschmidt@redhat.com>
PR target/60410
diff --git a/gcc/testsuite/g++.dg/init/const12.C b/gcc/testsuite/g++.dg/init/const12.C
new file mode 100644
index 0000000..2f6f9b2
--- /dev/null
+++ b/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];