From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1013 invoked by alias); 23 Aug 2011 15:48:04 -0000 Received: (qmail 995 invoked by uid 22791); 23 Aug 2011 15:48:03 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS 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; Tue, 23 Aug 2011 15:47:48 +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 p7NFllLs008432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Aug 2011 11:47:48 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7NFllFh022934 for ; Tue, 23 Aug 2011 11:47:47 -0400 Received: from [0.0.0.0] (ovpn-113-47.phx2.redhat.com [10.3.113.47]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p7NFlkmZ031688 for ; Tue, 23 Aug 2011 11:47:47 -0400 Message-ID: <4E53CBA2.2020501@redhat.com> Date: Tue, 23 Aug 2011 16:22:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110719 Thunderbird/5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for core issue 903 (C++11 null pointer constant) Content-Type: multipart/mixed; boundary="------------050703030606070901000405" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-08/txt/msg01912.txt.bz2 This is a multi-part message in MIME format. --------------050703030606070901000405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 728 C++11 greatly expands the set of constant expressions, which aggravates the existing issue with overloading and null pointer constants. If an expression could potentially be a constant expression, we need to find its constant value in order to determine how it interacts with overload resolution. In C++03 that doesn't involve much beyond the constant folding we already do, but in C++11 that means substituting into constexpr functions, so we decided to limit null pointer constants in C++11 to literal 0 (or 0L, etc). This patch doesn't attempt to treat things like 0+0 as non-null pointer constants yet, just avoids doing anything beyond the usual constant folding. Tested x86_64-pc-linux-gnu, applying to trunk. --------------050703030606070901000405 Content-Type: text/x-patch; name="core-903.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="core-903.patch" Content-length: 1433 commit af3382cf8702c1dfb5a98b2b2093aac21a5c4dff Author: Jason Merrill Date: Fri Aug 19 10:38:12 2011 -0400 Core 903 (partial) * call.c (null_ptr_cst_p): Only 0 qualifies in C++11. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d2700cb..e5f65b3 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -541,20 +541,14 @@ null_ptr_cst_p (tree t) return true; if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t))) { - if (cxx_dialect >= cxx0x) - { - t = fold_non_dependent_expr (t); - t = maybe_constant_value (t); - if (TREE_CONSTANT (t) && integer_zerop (t)) - return true; - } - else + /* Core issue 903 says only literal 0 is a null pointer constant. */ + if (cxx_dialect < cxx0x) { t = integral_constant_value (t); STRIP_NOPS (t); - if (integer_zerop (t) && !TREE_OVERFLOW (t)) - return true; } + if (integer_zerop (t) && !TREE_OVERFLOW (t)) + return true; } return false; } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-nullptr.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-nullptr.C index 7ac53db..6381323 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-nullptr.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-nullptr.C @@ -2,5 +2,5 @@ constexpr int zero() { return 0; } -void* ptr1 = zero(); // #1 -constexpr void* ptr2 = zero(); // #2 +void* ptr1 = zero(); // { dg-error "int" } +constexpr void* ptr2 = zero(); // { dg-error "int" } --------------050703030606070901000405--