From patchwork Wed Nov 9 17:41:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 124637 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]) by ozlabs.org (Postfix) with SMTP id AB8711007DB for ; Thu, 10 Nov 2011 04:41:50 +1100 (EST) Received: (qmail 25424 invoked by alias); 9 Nov 2011 17:41:49 -0000 Received: (qmail 25416 invoked by uid 22791); 9 Nov 2011 17:41:48 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Nov 2011 17:41:35 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA9HfZSX029566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Nov 2011 12:41:35 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pA9HfYBs009924 for ; Wed, 9 Nov 2011 12:41:35 -0500 Received: from [0.0.0.0] (ovpn-113-127.phx2.redhat.com [10.3.113.127]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pA9HfXnb012671 for ; Wed, 9 Nov 2011 12:41:34 -0500 Message-ID: <4EBABB4C.5000902@redhat.com> Date: Wed, 09 Nov 2011 12:41:32 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for various template non-type argument tests in C++11 mode 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 I'm improving the C++11 coverage of the testsuite, which resulted in several failures on non-type argument tests in the current testsuite. Fixed by folding constant expressions in fewer cases. Tested x86_64-pc-linux-gnu, applying to trunk. commit b1ec006abd6e4dbf45fca99160b09dab0827a10c Author: Jason Merrill Date: Tue Nov 8 20:36:49 2011 -0500 * pt.c (convert_nontype_argument): Only integral arguments get early folding. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 8c91a9e..38c26a7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5681,10 +5681,24 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) && (TYPE_PTR_P (type) || TYPE_PTR_TO_MEMBER_P (type))) expr = convert (type, expr); - /* In C++11, non-type template arguments can be arbitrary constant - expressions. But don't fold a PTRMEM_CST to a CONSTRUCTOR yet. */ - if (cxx_dialect >= cxx0x && TREE_CODE (expr) != PTRMEM_CST) - expr = maybe_constant_value (expr); + /* In C++11, integral or enumeration non-type template arguments can be + arbitrary constant expressions. Pointer and pointer to + member arguments can be general constant expressions that evaluate + to a null value, but otherwise still need to be of a specific form. */ + if (cxx_dialect >= cxx0x) + { + if (INTEGRAL_OR_ENUMERATION_TYPE_P (type)) + expr = maybe_constant_value (expr); + else if (TYPE_PTR_P (type) + || (TYPE_PTR_TO_MEMBER_P (type) + && TREE_CODE (expr) != PTRMEM_CST)) + { + tree folded = maybe_constant_value (expr); + if (TYPE_PTR_P (type) ? integer_zerop (folded) + : null_member_pointer_value_p (folded)) + expr = folded; + } + } /* HACK: Due to double coercion, we can get a NOP_EXPR(ADDR_EXPR (arg)) here,