From patchwork Sat Oct 17 18:57:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Maltsev X-Patchwork-Id: 531847 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 1DE6B1402B0 for ; Sun, 18 Oct 2015 05:57:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Vc9FD4U/; 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=jBsdJ00AAjrOtX0V5 epAu6kLuDX1RpuqgekaRSFtUCAddeMtSNCcrk6Y2SOHkOo5/qQc1njmyKF01DSMu 5HWw+tIRsm+4qERGtV64FeWQv7JBmh2YAdDd32BrpwPi3lOpS56ESLYYxHgklZF+ W2cA3PdkEIcGOwDjYFPoLc8sUE= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=6VB+UsUnwY7l+djXAwOU03X NAZk=; b=Vc9FD4U/C+fVJr4yI0ubsXKz0pz3fA/w6Rbjsj10Q2LBpPN6zDlgjKj QGeDSeTT7HDwOJzkdA1qXm6Af5Z7f36sDA+oF9Y+01dUbCt5ljyEx+n/vGuJit2C V+5T1XKWXEhSldtgleYFrto5kfCzSeqy5GNFalZyuOQUtXoD5qWM= Received: (qmail 105545 invoked by alias); 17 Oct 2015 18:57:47 -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 105529 invoked by uid 89); 17 Oct 2015 18:57:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 17 Oct 2015 18:57:45 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44757) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZnWfm-00053q-Ko for gcc-patches@gnu.org; Sat, 17 Oct 2015 14:57:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnWfi-0001Fk-W7 for gcc-patches@gnu.org; Sat, 17 Oct 2015 14:57:42 -0400 Received: from mail-lb0-x232.google.com ([2a00:1450:4010:c04::232]:33744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnWfi-0001F6-Nz for gcc-patches@gnu.org; Sat, 17 Oct 2015 14:57:38 -0400 Received: by lbbpp2 with SMTP id pp2so90843968lbb.0 for ; Sat, 17 Oct 2015 11:57:35 -0700 (PDT) X-Received: by 10.112.145.232 with SMTP id sx8mr6536550lbb.4.1445108255575; Sat, 17 Oct 2015 11:57:35 -0700 (PDT) Received: from [192.168.123.200] ([77.41.78.126]) by smtp.googlemail.com with ESMTPSA id v4sm608125lbo.30.2015.10.17.11.57.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Oct 2015 11:57:34 -0700 (PDT) Message-ID: <56229A1D.8080700@gmail.com> Date: Sat, 17 Oct 2015 21:57:33 +0300 From: Mikhail Maltsev User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: Jason Merrill , gcc-patches Subject: Re: [PATCH][C++] Fix PR67333 References: <55DF5684.8050607@gmail.com> <5613D0CA.1070706@redhat.com> In-Reply-To: <5613D0CA.1070706@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::232 X-IsSubscribed: yes On 10/06/2015 04:46 PM, Jason Merrill wrote: > Hi, sorry for the slow response. Please feel free to ping once a week. > > On 08/27/2015 02:27 PM, Mikhail Maltsev wrote: >> + if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval)) > > Why the !DECL_P check? Pulling the value out of a volatile INDIRECT_REF is just > as problematic as from a variable. Hmm... my intent was to check that we are not dealing with an expression, i.e. that should have been 'EXPR_P' rather than '!DECL_P'. I changed the condition to 'TREE_THIS_VOLATILE (t) && (EXPR_P (t) || want_rval)' and also added one more test (the one with 'test_ref' function). The updated patch passes bootstrap & regtest on x86_64-pc-linux-gnu. But now I wonder, if the combination 'TREE_THIS_VOLATILE (t) && EXPR_P (t) && !want_rval' is possible at all and should it be rejected? diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index ec9710c..b23d52a 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4006,7 +4006,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, return false; if (t == NULL_TREE) return true; - if (TREE_THIS_VOLATILE (t)) + if (TREE_THIS_VOLATILE (t) && (EXPR_P (t) || want_rval)) { if (flags & tf_error) error ("expression %qE has side-effects", t); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C new file mode 100644 index 0000000..885ece6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C @@ -0,0 +1,29 @@ +// PR c++/67333 +// { dg-do compile { target c++11 } } + +template +struct integral_constant +{ + static constexpr int value = N; +}; + +template +constexpr int lengthof (const volatile T (&)[S]) +{ + return S; +} + +template +constexpr int valueof (const volatile T (&s)[S]) // { dg-error "has side-effects" } +{ + return s[0]; +} + +int main () +{ + volatile int meow[4] {}; + integral_constant::value; // OK + integral_constant::value; // { dg-error "in a constant expression" } + return 0; +} + diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C new file mode 100644 index 0000000..333047a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C @@ -0,0 +1,36 @@ +// PR c++/67333 +// { dg-do compile { target c++14 } } + +template +struct integral_constant +{ + static constexpr int value = N; +}; + +constexpr int decl (int x) +{ + volatile int v = x; + return x; +} + +constexpr int use (int x) +{ + volatile int v = x; + return v; +} // { dg-error "has side-effects" } + +constexpr int test_ref (volatile int &x) +{ + volatile int &vol_ref = x; + volatile int *vol_ptr = &x; + volatile int &vol_deref = *vol_ptr; + return 0; +} + +int main() +{ + volatile int x = 0; + constexpr int t = test_ref (x); + integral_constant::value; // OK + integral_constant::value; // { dg-error "in a constant expression" } +}