From patchwork Fri Feb 5 22:32:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 579650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 18E77140B04 for ; Sat, 6 Feb 2016 09:32:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=pPS86im1; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Nax76AyPNkTIx6g8YZ7RBidoxk/bx5S0AbBcrKpSzwM6KJXL36LJN f/Crab1aNH+w7F5uw7/QEV788v4LPiQBz4WOhg1fWxXSdrznCXM+DEfkyaCAkk5B HMTNtWVguMk47MtziDoaGo7ONHzzH7HvXmiMs4KSMSqSc0GIONOSzU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=DCS+1O/jt3jcBTJRylRdO5+WwhU=; b=pPS86im1PLYCo0qAp+56 RKbOsfjNvPYdJO8R+j842AWzEfj5UVubSrD+XjBijDGt2LJXsdF4bLrZ3dsNaIEC VDKF715dG+RwCfIzeULScn2AtfyxMVrerjiNz6OpiC+IL9Xa00z7Tf4ak0BpZtYl rfptcpcyoCli/fO1NVNmEuw= Received: (qmail 64577 invoked by alias); 5 Feb 2016 22:32:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 64568 invoked by uid 89); 5 Feb 2016 22:32:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:maybe_c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 05 Feb 2016 22:32:48 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 4D8733B715 for ; Fri, 5 Feb 2016 22:32:47 +0000 (UTC) Received: from redhat.com (ovpn-204-103.brq.redhat.com [10.40.204.103]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u15MWhc1020177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 5 Feb 2016 17:32:46 -0500 Date: Fri, 5 Feb 2016 23:32:43 +0100 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/69688 (bogus error with -Wsign-compare) Message-ID: <20160205223243.GA3321@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) 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 PR c++/69688 * typeck2.c (store_init_value): Clear cv and fold caches. * g++.dg/init/const12.C: New test. Marek 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** 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];