{"id":2220863,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2220863/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260408095354.49694-1-iain@sandoe.co.uk/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/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},"msgid":"<20260408095354.49694-1-iain@sandoe.co.uk>","date":"2026-04-08T09:53:11","name":"c++, contracts: Account for lambda captures in pre/post [PR124648].","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"cf137e1098d09135662286683a599b40d18671da","submitter":{"id":80672,"url":"http://patchwork.ozlabs.org/api/1.1/people/80672/?format=json","name":"Iain Sandoe","email":"iains.gcc@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260408095354.49694-1-iain@sandoe.co.uk/mbox/","series":[{"id":499111,"url":"http://patchwork.ozlabs.org/api/1.1/series/499111/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=499111","date":"2026-04-08T09:53:11","name":"c++, contracts: Account for lambda captures in pre/post [PR124648].","version":1,"mbox":"http://patchwork.ozlabs.org/series/499111/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2220863/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220863/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=rfbDf/Qx;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=rfbDf/Qx","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.210.176"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frJLt25cZz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 08 Apr 2026 19:54:28 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id E9B894BA2E17\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  8 Apr 2026 09:54:26 +0000 (GMT)","from mail-pf1-f176.google.com (mail-pf1-f176.google.com\n [209.85.210.176])\n by sourceware.org (Postfix) with ESMTPS id 5AECE4BA2E08\n for <gcc-patches@gcc.gnu.org>; Wed,  8 Apr 2026 09:54:01 +0000 (GMT)","by mail-pf1-f176.google.com with SMTP id\n d2e1a72fcca58-82748257f5fso440171b3a.1\n for <gcc-patches@gcc.gnu.org>; Wed, 08 Apr 2026 02:54:01 -0700 (PDT)","from localhost.localdomain ([103.176.47.167])\n by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-82cf9b23c6asm26937640b3a.10.2026.04.08.02.53.57\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Wed, 08 Apr 2026 02:53:59 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org E9B894BA2E17","OpenDKIM Filter v2.11.0 sourceware.org 5AECE4BA2E08"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 5AECE4BA2E08","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 5AECE4BA2E08","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775642041; cv=none;\n b=NxFALKDdSZUMYfsrxvWE1keD+adzhEwuTAMte/fvbjQR9yaHdpHTOiav4OyojCbcOYHdPRAady7hi+vEoXOmG08Ro/TvztyCQ69COubO6H25SaJyTPzpAGdSr8gunHXspqiSg9S37Al2K/AGsGEcWwdd3OxfT5J+ume7G7T6qVY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775642041; c=relaxed/simple;\n bh=VCaINhjPH29C1CV4OWdRSAI8RTZDzYezZe5vVpMWjIE=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=aocPs05Ln/uD4/sgaJANSgjgBSCaNkGdh/xOTNGRRn70XPzxNuI9Ow5yNSSjMzchwO5b5KU/v8bn9gj5PtgBvtlwXaf6cgu+dbyBqrW4oZpv+X+bfLJSMbjS4ExRULBUX+uhMf5FWOwkU8A8bp/041T5L59aN6W5My7kap+Fl0U=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775642040; x=1776246840; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:reply-to:message-id:date\n :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=JqbuqeqrFrNXY/w5rpw6cb7YHKIlQf0aEYBCXlGQPYQ=;\n b=rfbDf/QxS+PX8dd6OkaelW0NeHHrM1VQq3KPLZX+mQntVxQohZPHJYnxr53EkSIccA\n KO3wRVweOLeGqiis23uKFX6pd3EQMViie90DCuinXFkcJVqE0F2olfsJ3MNwDCU4MCbl\n 200VQmqQMJ9MCxqoZFxtBh7Yt2O2uxOgIe8L0uD0TuzN/oXxYBGAfXAj+zglq2P8buhe\n QHj89ahmgjaEF4dJehIn9GVO7i+w+q2Ns/YIxKSryYs7yC7fsH6u3qDn9yJjgBx7210m\n KtIHp8XGCTsSbOZmH7vIirdhudFoU42aMPflgtwZlx5mniWHJHuQhqfLvmTAJ7SHUDvG\n KLwg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775642040; x=1776246840;\n h=content-transfer-encoding:mime-version:reply-to:message-id:date\n :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n :date:message-id:reply-to;\n bh=JqbuqeqrFrNXY/w5rpw6cb7YHKIlQf0aEYBCXlGQPYQ=;\n b=PsijqYK9e1WRrdVNLG+9zgr6KejT8x+kr+UcY3FTrgjk6IyDcV5DKCdwNvgJv3HsUb\n Xlf+3tSoh0/otqZvbdwqTcHpThnm8dMWWNK5noeCliyYQDujAeZNsMJi0S6KorXZqJWW\n ljeB7lBo3jxTyzq4NMvPobvNU+sH4TzrLUGXwtSVlCC2D/cP0/GrFxHo0zMfYAjvi/K7\n bt7BNvoBAsyGKsBH2tPcsJgWun4GzUON8rMUL0GFC3wMAj0YYBaDvY5jRcekoV8Dun68\n oY9R/yNiHigWOKMcqe9lC0G+uG3fAcv60lFtBadwSvBbPUz0TNIyjJjao2mDjPJKyqWL\n jwLQ==","X-Gm-Message-State":"AOJu0YyHw9R6iVgZNt1Ctk7RbLjiZwGuZ2SmrJsMJAo7gfFmOgSXD+Sk\n yrrZxKFqwgY3vOGovKgJRP8O5TPfSEYAEPpsRYJkL2FJu98IPSTxiewY3/33zQ==","X-Gm-Gg":"AeBDiev/eyWzBwBqupE/EEcU3fCuUKcBWOtv7mKURJLZ6Xv4bR2NiuAreT4r0axs9Vg\n FKNxbx4PQ8MDz7f6U7x3y1Bed6teMqQNWkiYgtZsREVjNGClkTKTAIjyOidc/BixezHJTURxmf8\n ekpq1j7Q7h9I9Si3Kw58k9DjdYXZaPHvWYNnXxSjoNTW87GvUyOHA5JgT46bRYcPzn3R5fKcTWY\n gFa1+ryEw5D4E6HyLgcYTRzDMple0wvwazKYK/KTgVsLPnyZFkBs/uccUhmgFiJ83o3D07StCDn\n fArgZFlFbTncT1+wa+D/7DsI1pgoFieS47e0+wY1KdhLSrnTof5Im5agc6lLsUJnzOl1SxjJpr0\n StaYUXhGjJSDsPt/uZ3ICLDr12WJvb8B7izq5uImZ0BNRCR9YuwFUJnPrOmPbi+2A0Mbpz2y9iH\n OcX38OC+8aHSxaaClWzHjrvpn9ED1siEC4KAdMDWbS9UE=","X-Received":"by 2002:a05:6a00:178e:b0:827:33cb:c7a3 with SMTP id\n d2e1a72fcca58-82d002359fbmr19682296b3a.10.1775642040131;\n Wed, 08 Apr 2026 02:54:00 -0700 (PDT)","From":"Iain Sandoe <iains.gcc@gmail.com>","X-Google-Original-From":"Iain Sandoe <iain@sandoe.co.uk>","To":"gcc-patches@gcc.gnu.org","Cc":"jason@redhat.com","Subject":"[PATCH] c++,\n contracts: Account for lambda captures in pre/post [PR124648].","Date":"Wed,  8 Apr 2026 15:23:11 +0530","Message-ID":"<20260408095354.49694-1-iain@sandoe.co.uk>","X-Mailer":"git-send-email 2.50.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"iain@sandoe.co.uk","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"This is a second issue that appears once the exclusion of implicit\nlambda captures is fixed.  Tested on x86_64-darwin, powerpc64le-linux\nOK for trunk/when?\nthanks\nIain\n\n--- 8< ---\n\nWhen we have lambda captures, they appear in the vars slot of a bind\nexpression at the outer operator() body.\n\nWe need these to be visible for any pre or post conditions that might\nuse them, therefore (when a lambda has captures) nest the application\nof contract pre and post conditions within the lambda outer bind\nexpression.\n\n\tPR c++/124648\n\ngcc/cp/ChangeLog:\n\n\t* contracts.cc (maybe_apply_function_contracts): Nest pre and\n\tpost conditions inside the outer bind expression of a lambda\n\twith captures.\n\nSigned-off-by: Iain Sandoe <iain@sandoe.co.uk>\n---\n gcc/cp/contracts.cc | 12 ++++++++++++\n 1 file changed, 12 insertions(+)","diff":"diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc\nindex d2dba3c62e6..760327d2020 100644\n--- a/gcc/cp/contracts.cc\n+++ b/gcc/cp/contracts.cc\n@@ -1352,6 +1352,18 @@ maybe_apply_function_contracts (tree fndecl)\n       DECL_SAVED_TREE (fndecl) = push_stmt_list ();\n     }\n \n+  /* If we have a lambda with captures, ensure that those captures are in-\n+     scope for pre and post conditions.  */\n+  if (LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl))\n+      && TREE_CODE (fnbody) == BIND_EXPR)\n+    {\n+      tree extract = BIND_EXPR_BODY (fnbody);\n+      BIND_EXPR_BODY (fnbody) = NULL_TREE;\n+      add_stmt (fnbody);\n+      BIND_EXPR_BODY (fnbody) = push_stmt_list ();\n+      fnbody = extract;\n+    }\n+\n   /* Now add the pre and post conditions to the existing function body.\n      This copies the approach used for function try blocks.  */\n   tree compound_stmt = begin_compound_stmt (0);\n","prefixes":[]}