{"id":807251,"url":"http://patchwork.ozlabs.org/api/1.2/patches/807251/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/CADzB+2n+GPkqp4u-6L0W1k4PH04N6o-eSTdaBmtm9GuAchAAkQ@mail.gmail.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.2/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<CADzB+2n+GPkqp4u-6L0W1k4PH04N6o-eSTdaBmtm9GuAchAAkQ@mail.gmail.com>","list_archive_url":null,"date":"2017-08-29T19:48:01","name":"C++ PATCH for c++/80935, wrong error on lambda in C++17 mode","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"10ea232da87e8d5b33999bac90fee066a289c22f","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/1.2/people/4337/?format=json","name":"Jason Merrill","email":"jason@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/CADzB+2n+GPkqp4u-6L0W1k4PH04N6o-eSTdaBmtm9GuAchAAkQ@mail.gmail.com/mbox/","series":[{"id":453,"url":"http://patchwork.ozlabs.org/api/1.2/series/453/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=453","date":"2017-08-29T19:48:01","name":"C++ PATCH for c++/80935, wrong error on lambda in C++17 mode","version":1,"mbox":"http://patchwork.ozlabs.org/series/453/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/807251/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807251/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-return-461115-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461115-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"uiUjkk7Y\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xhfMp4SXJz9sQl\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 30 Aug 2017 05:48:49 +1000 (AEST)","(qmail 80800 invoked by alias); 29 Aug 2017 19:48:39 -0000","(qmail 80283 invoked by uid 89); 29 Aug 2017 19:48:26 -0000","from mail-io0-f180.google.com (HELO mail-io0-f180.google.com)\n\t(209.85.223.180) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tTue, 29 Aug 2017 19:48:24 +0000","by mail-io0-f180.google.com with SMTP id d81so24984720ioj.4 for\n\t<gcc-patches@gcc.gnu.org>; Tue, 29 Aug 2017 12:48:23 -0700 (PDT)","by 10.107.181.23 with HTTP; Tue, 29 Aug 2017 12:48:01 -0700 (PDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:from:date:message-id:subject:to:content-type; q=\n\tdns; s=default; b=PnWE0valQDwhYaoTEqD6bmULJ6ew0aXdCJJ0IjPI/Vm66E\n\tpMvVqPO5ywwoz3W2Iivqz4DLc1wtU2finRfuJxZgl62AUwr+srXN4D8qnHhTno2q\n\tBDPjwvBLouEkeSSRZzoPGTgRKpr6W2O/KfClNZVlSbOHHSFLALn8ATBKCCS+Q=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:from:date:message-id:subject:to:content-type; s=\n\tdefault; bh=Wdxyapb5DgqrzJjgIyNC0i4lqfo=; b=uiUjkk7YqV/TUokOzLvu\n\ty2rei1GehjJe228d9AwFn8pNYAGH2Maid0nasIz5XvobeSyXBupqmW0WtiCoUwqg\n\tzMr5L3oe0NaF2UNeF9ycsdKttNZcbEZRbp68HVvSEq2ORMZpg88zznOEAgOJQlUU\n\t+52Pd+BXniYPbHKhHb4Yk6Q=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-24.1 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=","X-HELO":"mail-io0-f180.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:mime-version:from:date:message-id:subject:to;\n\tbh=/WTCjYcT+zgXmFo/A0bgdLUP2O2VW5+ta15KhMovIQY=;\n\tb=IN2VsCA8GBs+EELaJxlhhZoDBXsYpQxUTweTSs+6crN+m6LBoBG5ZUHCXDKTu80UQg\n\tWGBcgXT9krdW/LnVh28M9Qi7n75l304p5+rQh4rOH1AJJtemQkzN8QAmxkgJLzPnIcip\n\tyKD7uyvP+tuaqrhJJuZDhUaHTxPxyVv0/l0H1Tqz2NiL0YZWSQsU50CJ6u6PATTBkZRe\n\tHnyqD1FA2ZiiuXBe6YYdC1HvvDH00zpByloZbPWM/lI1eVR0aWOTN32/G4kBZ+6GmExr\n\tySbrmv7oytPFkvR5jga3XmF6r1dhU/HqCSK3OqI2Er5gnbVI7m7+3bX4oG/9okCi3Qal\n\t9hww==","X-Gm-Message-State":"AHYfb5goll0WMeDGOZUqrLBgBKMiabtPubyjN7r1xFOtsmcabOXkWuQA\taiTm+vDjdEi8AQrDBdF+7hGbsDP3twm7xqQ=","X-Received":"by 10.107.53.150 with SMTP id k22mr4999758ioo.285.1504036101888;\n\tTue, 29 Aug 2017 12:48:21 -0700 (PDT)","MIME-Version":"1.0","From":"Jason Merrill <jason@redhat.com>","Date":"Tue, 29 Aug 2017 15:48:01 -0400","Message-ID":"<CADzB+2n+GPkqp4u-6L0W1k4PH04N6o-eSTdaBmtm9GuAchAAkQ@mail.gmail.com>","Subject":"C++ PATCH for c++/80935, wrong error on lambda in C++17 mode","To":"gcc-patches List <gcc-patches@gcc.gnu.org>","Content-Type":"multipart/mixed; boundary=\"001a1144947e9598320557e9b1fd\"","X-IsSubscribed":"yes"},"content":"In this testcase, trying to treat a lambda op() as a constexpr\nfunction led to an inappropriate error; we should instead just decide\nthat it isn't constexpr after all.\n\nThis patch also tweaks a couple of other places to use\nis_instantiation_of_constexpr and var_in_maybe_constexpr_fn\nappropriately.\n\nTested x86_64-pc-linux-gnu, applying to trunk.\ncommit 5eeca22016ed9ff34e83afb88e8195796096acae\nAuthor: Jason Merrill <jason@redhat.com>\nDate:   Tue Aug 29 15:45:47 2017 -0400\n\n            PR c++/80935 - wrong C++17 error with lambda\n    \n            * decl.c (check_for_uninitialized_const_var): Check\n            is_instantiation_of_constexpr.\n            * constexpr.c (ensure_literal_type_for_constexpr_object): Check\n            is_instantiation_of_constexpr.\n            (potential_constant_expression_1): Check var_in_maybe_constexpr_fn.","diff":"diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c\nindex daeec9d..f3e868c 100644\n--- a/gcc/cp/constexpr.c\n+++ b/gcc/cp/constexpr.c\n@@ -100,7 +100,7 @@ ensure_literal_type_for_constexpr_object (tree decl)\n \t    }\n \t  else\n \t    {\n-\t      if (!DECL_TEMPLATE_INSTANTIATION (current_function_decl))\n+\t      if (!is_instantiation_of_constexpr (current_function_decl))\n \t\t{\n \t\t  error (\"variable %qD of non-literal type %qT in %<constexpr%> \"\n \t\t\t \"function\", decl, type);\n@@ -5335,8 +5335,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,\n         STRIP_NOPS (x);\n         if (is_this_parameter (x) && !is_capture_proxy (x))\n \t  {\n-\t    if (DECL_CONTEXT (x)\n-\t\t&& !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))\n+\t    if (!var_in_maybe_constexpr_fn (x))\n \t      {\n \t\tif (flags & tf_error)\n \t\t  error_at (loc, \"use of %<this%> in a constant expression\");\ndiff --git a/gcc/cp/decl.c b/gcc/cp/decl.c\nindex ff3127e..23829b0 100644\n--- a/gcc/cp/decl.c\n+++ b/gcc/cp/decl.c\n@@ -5525,9 +5525,10 @@ check_for_uninitialized_const_var (tree decl)\n \t\t   \"uninitialized const %qD\", decl);\n       else\n \t{\n-\t  error_at (DECL_SOURCE_LOCATION (decl),\n-\t\t    \"uninitialized variable %qD in %<constexpr%> function\",\n-\t\t    decl);\n+\t  if (!is_instantiation_of_constexpr (current_function_decl))\n+\t    error_at (DECL_SOURCE_LOCATION (decl),\n+\t\t      \"uninitialized variable %qD in %<constexpr%> function\",\n+\t\t      decl);\n \t  cp_function_chain->invalid_constexpr = true;\n \t}\n \ndiff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda16.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda16.C\nnew file mode 100644\nindex 0000000..ad5d885\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda16.C\n@@ -0,0 +1,16 @@\n+// PR c++/80642\n+// { dg-do compile { target c++14 } }\n+\n+int main()\n+{\n+  [](auto i)\n+    {\n+      if (i)\n+        {\n+\t  int j;\n+\t  static int k;\n+\t  return i + j;\n+        }\n+      return i;\n+    }(0);\n+}\n","prefixes":[]}