From patchwork Thu Apr 25 16:18:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 239561 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 0D3122C00EB for ; Fri, 26 Apr 2013 02:18:46 +1000 (EST) 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:cc:subject:content-type; q=dns; s=default; b=rw/SliQQkw5G/Xbdfb+sxjemyiJUzOTfbAiAYr6JFVj pDmXEJyeP6WyrNAC6Pl4pBclBvi164cIozKum6/d+ZgO4A0w1JqkCN5d7I0Kpa1c X1MFq6l8ZeSYi7lcJlu2IURdBHSu0X/4g8BWWFw09KCfM4dWOVQoV/rKCHCRDy34 = 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:cc:subject:content-type; s=default; bh=DSSUAbx+JHkzE7PjqTF2gLLzb5w=; b=V0ldy4PG6UFC+Et1f z2X72g8Hr32EhUSqqJBUr7o/8QHLiVgrx/hbl05F8a70y4TEg5dnIZcIRjoIpgi1 q/1XJiGPOG6cylwRs+JXtMb3hYkHPOfsoG1UaG2HmlOWfblnZv2QDjM/6NWuvp2t tShpHyBkzye6CyFwcLrB0yRIc8= Received: (qmail 20430 invoked by alias); 25 Apr 2013 16:18:39 -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 20420 invoked by uid 89); 25 Apr 2013 16:18:39 -0000 X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 25 Apr 2013 16:18:38 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3PGIbQV022285 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Apr 2013 12:18:37 -0400 Received: from [10.3.113.66] (ovpn-113-66.phx2.redhat.com [10.3.113.66]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3PGIavN024721; Thu, 25 Apr 2013 12:18:37 -0400 Message-ID: <5179575C.7020805@redhat.com> Date: Thu, 25 Apr 2013 12:18:36 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List CC: Dodji Seketeli Subject: C++ PATCH for c++/56859 (alignas and value-dependent expressions) X-Virus-Found: No Leaving value-dependent expressions alone doesn't work if you then silently turn them into error_mark_node because they aren't INTEGER_CST. And while I'm in this code, there's no need to check the result of cxx_constant_value, as it already returns error_mark_node for non-constant expressions. Tested x86_64-pc-linux-gnu, applying to trunk and 4.8. commit 66d07cda5155f2713de7f5e85a37062210c7c0b4 Author: Jason Merrill Date: Wed Apr 24 21:13:50 2013 -0400 PR c++/56859 * typeck.c (cxx_alignas_expr): Handle value-dependence properly. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 84da5de..b761dd5 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1725,15 +1725,19 @@ cxx_alignas_expr (tree e) When the alignment-specifier is of the form alignas(type-id ), it shall have the same effect as - alignas( alignof(type-id )). */ + alignas(alignof(type-id )). */ return cxx_sizeof_or_alignof_type (e, ALIGNOF_EXPR, false); - /* If we reach this point, it means the alignas expression if of the form "alignas(assignment-expression)", so we should follow what is stated by [dcl.align]/2. */ + if (value_dependent_expression_p (e)) + /* Leave value-dependent expression alone for now. */ + return e; + + e = fold_non_dependent_expr (e); e = mark_rvalue_use (e); /* [dcl.align]/2 says: @@ -1741,18 +1745,7 @@ cxx_alignas_expr (tree e) the assignment-expression shall be an integral constant expression. */ - e = fold_non_dependent_expr (e); - if (value_dependent_expression_p (e)) - /* Leave value-dependent expression alone for now. */; - else - e = cxx_constant_value (e); - - if (e == NULL_TREE - || e == error_mark_node - || TREE_CODE (e) != INTEGER_CST) - return error_mark_node; - - return e; + return cxx_constant_value (e); } diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-54.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-54.C new file mode 100644 index 0000000..45aa8e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-54.C @@ -0,0 +1,14 @@ +// PR c++/56859 +// { dg-require-effective-target c++11 } + +template +struct aligned_storage +{ + using type = struct { alignas(alignment) unsigned char data[size]; }; +}; + +#define SA(X) static_assert((X),#X) +SA(alignof(aligned_storage<8,1>::type) == 1); +SA(alignof(aligned_storage<8,2>::type) == 2); +SA(alignof(aligned_storage<8,4>::type) == 4); +SA(alignof(aligned_storage<8,8>::type) == 8);