From patchwork Wed Mar 23 18:22:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 601319 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 3qVdFz72Ndz9rxv for ; Thu, 24 Mar 2016 05:22:30 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=asxCi6AM; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=TGS41890yq1HyPc3O2J+cVXUtKahMh+cIyiAO6wzmQJzl3pesj sSJoglYmGGqyfOS6w4Z7PZ4ERvB/UP9Aa/czF+p90iTYVBfSYJL9Shf5Hd2KwtGr UOVkfIJ7PB7BZ5G8ALY9zGau6myELysdM2ax2lbkzSUvwNMToIdwga4AQ= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=ngwhq/WfsOG+TTbvOz2OusnPo0I=; b=asxCi6AMaVhzD/CbLH7K TChKlWjSqNFKlw2VHI+C4LZSwIBgybezoyR6Xejo3JNe7F7BVP3EN1E3zNsS+mu3 k9fzL0ukDzDqkLIM6mcvJE0s2eBVRhe1pSiLpJuAQZlEgoIoqZSnTAdioBS+8u94 tvQwbIgU9Da/0xXtNbMLO3I= Received: (qmail 107336 invoked by alias); 23 Mar 2016 18:22:22 -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 107326 invoked by uid 89); 23 Mar 2016 18:22:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=sk:constex, Hx-languages-length:1809, i1 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 23 Mar 2016 18:22:20 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 2E04B29ACD for ; Wed, 23 Mar 2016 18:22:19 +0000 (UTC) Received: from [10.3.113.58] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2NIMHln021506 for ; Wed, 23 Mar 2016 14:22:18 -0400 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH for c++/70344 (ICE with recursive constexpr) Message-ID: <56F2DED8.2070407@redhat.com> Date: Wed, 23 Mar 2016 14:22:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 cp_fold tries to fold calls to constexpr functions. When we are inside a constexpr function at the time and see a call to the same function, this caused trouble because we hadn't adjusted the parameter types yet. Fixed by handling this special case of calling a constexpr function that isn't defined yet. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4d4c5c65269b6dcde93fa13a90f2af925c8082c7 Author: Jason Merrill Date: Wed Mar 23 13:51:42 2016 -0400 PR c++/70344 * constexpr.c (cxx_eval_call_expression): Catch invalid recursion. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 7b13633..d71e488 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1239,6 +1239,21 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, return t; } + if (fun == current_function_decl) + { + /* A call to the current function, i.e. + constexpr int f (int i) { + constexpr int j = f(i-1); + return j; + } + This would be OK without the constexpr on the declaration of j. */ + if (!ctx->quiet) + error_at (loc, "%qD called in a constant expression before its " + "definition is complete", fun); + *non_constant_p = true; + return t; + } + constexpr_ctx new_ctx = *ctx; if (DECL_CONSTRUCTOR_P (fun) && !ctx->object && TREE_CODE (t) == AGGR_INIT_EXPR) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C new file mode 100644 index 0000000..978b998 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C @@ -0,0 +1,17 @@ +// PR c++/70344 +// { dg-do compile { target c++11 } } + +struct Z +{ + Z () = default; + Z (Z const &) = default; + constexpr Z (Z &&) {} +}; + +constexpr int +fn (Z v) +{ + return fn (v); +} + +auto t = fn (Z ());