From patchwork Wed Jun 29 17:18:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 102642 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 DA5BBB6F59 for ; Thu, 30 Jun 2011 03:18:56 +1000 (EST) Received: (qmail 29751 invoked by alias); 29 Jun 2011 17:18:52 -0000 Received: (qmail 29739 invoked by uid 22791); 29 Jun 2011 17:18:49 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 29 Jun 2011 17:18:29 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5THISi3001159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 29 Jun 2011 13:18:28 -0400 Received: from [127.0.0.1] (ovpn-113-39.phx2.redhat.com [10.3.113.39]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5THISiP019175 for ; Wed, 29 Jun 2011 13:18:28 -0400 Message-ID: <4E0B5E63.5010205@redhat.com> Date: Wed, 29 Jun 2011 13:18:27 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49520 (bogus error with using in constexpr) 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 A CLEANUP_POINT_EXPR wraps each statement, so we need to strip it at a lower level. Tested x86_64-pc-linux-gnu, applied to trunk. commit 505b4baa3619375d81b409f9ff2bde95cce0f50a Author: Jason Merrill Date: Wed Jun 29 12:43:19 2011 -0400 PR c++/49520 * semantics.c (constexpr_fn_retval): Handle CLEANUP_POINT_EXPR here. (massage_constexpr_body): Not here. diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index 12c01cb..bb1b753 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -207,7 +207,7 @@ DEFTREECODE (UNBOUND_CLASS_TEMPLATE, "unbound_class_template", tcc_type, 0) DEFTREECODE (USING_DECL, "using_decl", tcc_declaration, 0) /* A using directive. The operand is USING_STMT_NAMESPACE. */ -DEFTREECODE (USING_STMT, "using_directive", tcc_statement, 1) +DEFTREECODE (USING_STMT, "using_stmt", tcc_statement, 1) /* An un-parsed default argument. Holds a vector of input tokens and a vector of places where the argument was instantiated before diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fb984d4..ad68a01 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5657,6 +5657,9 @@ constexpr_fn_retval (tree body) return NULL_TREE; return error_mark_node; + case CLEANUP_POINT_EXPR: + return constexpr_fn_retval (TREE_OPERAND (body, 0)); + case USING_STMT: return NULL_TREE; @@ -5683,8 +5686,6 @@ massage_constexpr_body (tree fun, tree body) body = EH_SPEC_STMTS (body); if (TREE_CODE (body) == MUST_NOT_THROW_EXPR) body = TREE_OPERAND (body, 0); - if (TREE_CODE (body) == CLEANUP_POINT_EXPR) - body = TREE_OPERAND (body, 0); body = constexpr_fn_retval (body); } return body; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-using2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-using2.C new file mode 100644 index 0000000..6b28281 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-using2.C @@ -0,0 +1,18 @@ +// PR c++/49520 +// { dg-options -std=c++0x } + +namespace x { void foo(); } + +template +struct traits +{ + static constexpr bool f() { return true; } + + static constexpr bool g() + { + using x::foo; + return f() && noexcept(foo()); + } +}; + +template struct traits;