From patchwork Tue Aug 29 19:48:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 807251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461115-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uiUjkk7Y"; dkim-atps=neutral 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 3xhfMp4SXJz9sQl for ; Wed, 30 Aug 2017 05:48:49 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=PnWE0valQDwhYaoTEqD6bmULJ6ew0aXdCJJ0IjPI/Vm66E pMvVqPO5ywwoz3W2Iivqz4DLc1wtU2finRfuJxZgl62AUwr+srXN4D8qnHhTno2q BDPjwvBLouEkeSSRZzoPGTgRKpr6W2O/KfClNZVlSbOHHSFLALn8ATBKCCS+Q= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=Wdxyapb5DgqrzJjgIyNC0i4lqfo=; b=uiUjkk7YqV/TUokOzLvu y2rei1GehjJe228d9AwFn8pNYAGH2Maid0nasIz5XvobeSyXBupqmW0WtiCoUwqg zMr5L3oe0NaF2UNeF9ycsdKttNZcbEZRbp68HVvSEq2ORMZpg88zznOEAgOJQlUU +52Pd+BXniYPbHKhHb4Yk6Q= Received: (qmail 80800 invoked by alias); 29 Aug 2017 19:48: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 80283 invoked by uid 89); 29 Aug 2017 19:48:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f180.google.com Received: from mail-io0-f180.google.com (HELO mail-io0-f180.google.com) (209.85.223.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 19:48:24 +0000 Received: by mail-io0-f180.google.com with SMTP id d81so24984720ioj.4 for ; Tue, 29 Aug 2017 12:48:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=/WTCjYcT+zgXmFo/A0bgdLUP2O2VW5+ta15KhMovIQY=; b=IN2VsCA8GBs+EELaJxlhhZoDBXsYpQxUTweTSs+6crN+m6LBoBG5ZUHCXDKTu80UQg WGBcgXT9krdW/LnVh28M9Qi7n75l304p5+rQh4rOH1AJJtemQkzN8QAmxkgJLzPnIcip yKD7uyvP+tuaqrhJJuZDhUaHTxPxyVv0/l0H1Tqz2NiL0YZWSQsU50CJ6u6PATTBkZRe HnyqD1FA2ZiiuXBe6YYdC1HvvDH00zpByloZbPWM/lI1eVR0aWOTN32/G4kBZ+6GmExr ySbrmv7oytPFkvR5jga3XmF6r1dhU/HqCSK3OqI2Er5gnbVI7m7+3bX4oG/9okCi3Qal 9hww== X-Gm-Message-State: AHYfb5goll0WMeDGOZUqrLBgBKMiabtPubyjN7r1xFOtsmcabOXkWuQA aiTm+vDjdEi8AQrDBdF+7hGbsDP3twm7xqQ= X-Received: by 10.107.53.150 with SMTP id k22mr4999758ioo.285.1504036101888; Tue, 29 Aug 2017 12:48:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.181.23 with HTTP; Tue, 29 Aug 2017 12:48:01 -0700 (PDT) From: Jason Merrill Date: Tue, 29 Aug 2017 15:48:01 -0400 Message-ID: Subject: C++ PATCH for c++/80935, wrong error on lambda in C++17 mode To: gcc-patches List X-IsSubscribed: yes In this testcase, trying to treat a lambda op() as a constexpr function led to an inappropriate error; we should instead just decide that it isn't constexpr after all. This patch also tweaks a couple of other places to use is_instantiation_of_constexpr and var_in_maybe_constexpr_fn appropriately. Tested x86_64-pc-linux-gnu, applying to trunk. commit 5eeca22016ed9ff34e83afb88e8195796096acae Author: Jason Merrill Date: Tue Aug 29 15:45:47 2017 -0400 PR c++/80935 - wrong C++17 error with lambda * decl.c (check_for_uninitialized_const_var): Check is_instantiation_of_constexpr. * constexpr.c (ensure_literal_type_for_constexpr_object): Check is_instantiation_of_constexpr. (potential_constant_expression_1): Check var_in_maybe_constexpr_fn. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index daeec9d..f3e868c 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -100,7 +100,7 @@ ensure_literal_type_for_constexpr_object (tree decl) } else { - if (!DECL_TEMPLATE_INSTANTIATION (current_function_decl)) + if (!is_instantiation_of_constexpr (current_function_decl)) { error ("variable %qD of non-literal type %qT in % " "function", decl, type); @@ -5335,8 +5335,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, STRIP_NOPS (x); if (is_this_parameter (x) && !is_capture_proxy (x)) { - if (DECL_CONTEXT (x) - && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x))) + if (!var_in_maybe_constexpr_fn (x)) { if (flags & tf_error) error_at (loc, "use of % in a constant expression"); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index ff3127e..23829b0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5525,9 +5525,10 @@ check_for_uninitialized_const_var (tree decl) "uninitialized const %qD", decl); else { - error_at (DECL_SOURCE_LOCATION (decl), - "uninitialized variable %qD in % function", - decl); + if (!is_instantiation_of_constexpr (current_function_decl)) + error_at (DECL_SOURCE_LOCATION (decl), + "uninitialized variable %qD in % function", + decl); cp_function_chain->invalid_constexpr = true; } diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda16.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda16.C new file mode 100644 index 0000000..ad5d885 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda16.C @@ -0,0 +1,16 @@ +// PR c++/80642 +// { dg-do compile { target c++14 } } + +int main() +{ + [](auto i) + { + if (i) + { + int j; + static int k; + return i + j; + } + return i; + }(0); +}