From patchwork Thu Aug 27 18:27:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Maltsev X-Patchwork-Id: 511390 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 94E23140129 for ; Fri, 28 Aug 2015 04:27:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=DcRESdgu; 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:content-type; q= dns; s=default; b=KwYVvbH8LZ9qDqFHrjK8/YP3m3d3O6j3Smsc5VMoUm2AWF xKy5KLm5smq+V0GLM/chtJuQDjd3hB7ax5x+UcRCHgWs4zabXvq/8d1MhElbNjBQ Z6hu2aIqaanOvM9b/jgJpVCxhZdNqSnAgHM7F1NbNFfR1+o4+fUGqk2PqKpoA= 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:content-type; s= default; bh=nbzwPe408ym4DRshh4oeWTz/UyQ=; b=DcRESdguk/+3uURV0mtA 7Ei7oPjdsD3HIhZOAHio6ebM+eeQrc9BqQp+kF7S117TnfCW+ICBA0eHHo1WAH5y 7YCWUSK9uHUSlho1XtW4Nukcid/UW+g7RWtZLQa8NDdZcXkKkBMfmPTiXOWA1GII KUE1UjoBr6Ni+DUOpSnV9E0= Received: (qmail 70768 invoked by alias); 27 Aug 2015 18:27:25 -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 70734 invoked by uid 89); 27 Aug 2015 18:27:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RP_MATCHES_RCVD, SPF_PASS 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; Thu, 27 Aug 2015 18:27:23 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52051) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZV1tR-0000Ou-HH for gcc-patches@gnu.org; Thu, 27 Aug 2015 14:27:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZV1tP-0003B9-JU for gcc-patches@gnu.org; Thu, 27 Aug 2015 14:27:20 -0400 Received: from mail-lb0-x229.google.com ([2a00:1450:4010:c04::229]:35587) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZV1tP-00037V-CK for gcc-patches@gnu.org; Thu, 27 Aug 2015 14:27:19 -0400 Received: by lbcbn3 with SMTP id bn3so16727647lbc.2 for ; Thu, 27 Aug 2015 11:27:17 -0700 (PDT) X-Received: by 10.112.141.136 with SMTP id ro8mr2941587lbb.88.1440700037714; Thu, 27 Aug 2015 11:27:17 -0700 (PDT) Received: from ?IPv6:2a00:1148:b0ba:629:e23f:49ff:fe10:1e6b? ([2a00:1148:b0ba:629:e23f:49ff:fe10:1e6b]) by smtp.googlemail.com with ESMTPSA id tv6sm773492lbb.31.2015.08.27.11.27.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Aug 2015 11:27:16 -0700 (PDT) Message-ID: <55DF5684.8050607@gmail.com> Date: Thu, 27 Aug 2015 21:27:16 +0300 From: Mikhail Maltsev User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: gcc-patches , Jason Merrill Subject: [PATCH][C++] Fix PR67333 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::229 X-IsSubscribed: yes Hi. This patch fixes a rejects-valid bug related to volatile-qualified arguments of constexpr functions. This is essentially a one-line change in constexpr.c. Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk? gcc/cp/ChangeLog: 2015-08-25 Mikhail Maltsev PR c++/67333 * constexpr.c (potential_constant_expression_1): Do not reject volatile-qualified values, if there is no lvalue-to-rvalue conversion. gcc/testsuite/ChangeLog: 2015-08-25 Mikhail Maltsev PR c++/67333 * g++.dg/cpp0x/constexpr-67333.C: New test. * g++.dg/cpp1y/constexpr-67333.C: New test. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 1eacb8b..f4ee727 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) && (!DECL_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..7e3ef21 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C @@ -0,0 +1,26 @@ +// 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" } + +int main() +{ + integral_constant::value; // OK + integral_constant::value; // { dg-error "in a constant expression" } +}