Message ID | 20160205223243.GA3321@redhat.com |
---|---|
State | New |
Headers | show |
On 02/05/2016 05:32 PM, Marek Polacek wrote: > 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)) This should happen after computing the value to be stored, not before. Also, could you combine those two functions into one? There's no reason for callers such as this to need to call two different functions. Jason
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];