{"id":2233039,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2233039/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260505151030.1749548-11-waffl3x@baylibre.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":"<20260505151030.1749548-11-waffl3x@baylibre.com>","list_archive_url":null,"date":"2026-05-05T15:02:03","name":"[10/12] OpenMP/C++: Sorry for static vars in implicit constexpr functions","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"75f3355dba4bf3b33a8241984b08eb08be925375","submitter":{"id":90070,"url":"http://patchwork.ozlabs.org/api/1.2/people/90070/?format=json","name":"Waffl3x","email":"waffl3x@baylibre.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260505151030.1749548-11-waffl3x@baylibre.com/mbox/","series":[{"id":502853,"url":"http://patchwork.ozlabs.org/api/1.2/series/502853/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=502853","date":"2026-05-05T15:01:54","name":"OpenMP/C++: 'allocate' directive","version":1,"mbox":"http://patchwork.ozlabs.org/series/502853/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233039/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2233039/checks/","tags":{},"related":[],"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=baylibre-com.20251104.gappssmtp.com\n header.i=@baylibre-com.20251104.gappssmtp.com header.a=rsa-sha256\n header.s=20251104 header.b=fbs7yF6j;\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=baylibre-com.20251104.gappssmtp.com\n header.i=@baylibre-com.20251104.gappssmtp.com header.a=rsa-sha256\n header.s=20251104 header.b=fbs7yF6j","sourceware.org;\n dmarc=none (p=none dis=none) header.from=baylibre.com","sourceware.org; spf=pass smtp.mailfrom=baylibre.com","server2.sourceware.org;\n arc=none smtp.remote-ip=2607:f8b0:4864:20::434"],"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 4g926Y4FGYz1yJ0\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 01:11:49 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 913A94BA9024\n\tfor <incoming@patchwork.ozlabs.org>; Tue,  5 May 2026 15:11:47 +0000 (GMT)","from mail-pf1-x434.google.com (mail-pf1-x434.google.com\n [IPv6:2607:f8b0:4864:20::434])\n by sourceware.org (Postfix) with ESMTPS id 3AA284BA9015\n for <gcc-patches@gcc.gnu.org>; Tue,  5 May 2026 15:10:47 +0000 (GMT)","by mail-pf1-x434.google.com with SMTP id\n d2e1a72fcca58-824bcb2011bso402946b3a.3\n for <gcc-patches@gcc.gnu.org>; Tue, 05 May 2026 08:10:47 -0700 (PDT)","from waffl3x-prestige.lan ([2001:56a:f98a:b800:1f67:ce08:3cbd:86b8])\n by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-83965645140sm2674956b3a.12.2026.05.05.08.10.45\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 05 May 2026 08:10:45 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 913A94BA9024","OpenDKIM Filter v2.11.0 sourceware.org 3AA284BA9015"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 3AA284BA9015","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 3AA284BA9015","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777993847; cv=none;\n b=YCm2yas2HJHMr1qX/2ctDMbP6QwgrHLitbex6vsb2bo7p3cvO6qOhB3w3IZzgU5X7vpc2nH8TG2islspY4oKA2qxs07b3IkdfCOdNYRsKC/Oiz/yB7zfrGBz+hrkarQPNEtqAhbuR6ddptMPhU3VrzkpqFMy97S5TvVMNfRTwFY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777993847; c=relaxed/simple;\n bh=Kna5+Cor/te1sZtXxX2oI5hB/o5BleSnr6hMy7ueeus=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=Q8mNI1SebV5Iiv2/+fEXyIPhR6WNjt0JDXVxXbW8nizWNMXKAE2ptHDNr/A3qtMT86WIgYtfszZudRcRUhgB2AAJo09/UO3ly/NVVIdS3VtXBRhkWWNyZ1L5pbiya52Q3iktyph0pBRZ7FSArhMTJkprKouF4FK5K/H2d+6e6c0=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=baylibre-com.20251104.gappssmtp.com; s=20251104; t=1777993846;\n x=1778598646;\n darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=/7iIZJ6yg9dbw712Gkpi2hxoOh6zcaAuFSfPFhAtNzA=;\n b=fbs7yF6jve11Zi0tGce54JM6rzQRTIbeKEOhQGOtW84XbecI9+9De26sqZhqQqFgHf\n i4JxcVeRGX31gU8sI0eGyFCyB9Xxe1hAF5KnKJU1bO/H+TT8VBQDiUNmcVD6NAtRDRl/\n /+r6Q2KYB+vghgss0UIEgWQF7WWFSjyZj4OtqtKGGColxALB9dZJZG+BpNNUqitsS4Mx\n ztra8LMSGKyRFG78ZyPLtgSDmBpKLMhEZoiUyFHIkaoNy5SIPrXD/Ny0nLHAc2AJJT+7\n gQHJTxrvnVngGV2XcvBpqq5DDVCAAnU0HU/K9BaVPzZsyn3GqgWXTdvcAL95tRD1dXC8\n aJaA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777993846; x=1778598646;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=/7iIZJ6yg9dbw712Gkpi2hxoOh6zcaAuFSfPFhAtNzA=;\n b=YMSsSok1SREPUb2Gf5Cppuby70y4VLBnqUILcR6Jqk7jlE4DE257bUdv3FAG+svHmQ\n rQO7ZQEt8bbxqj1BiHfpCdYuaRyR+ltQUjH8AQGsDPgr3zIFjffPZJCbJTse055peQqY\n aJJqza/mrBF9UMOYkSMf3UW62NJbazVO40GZRHbDTzJDVljZmiRZ2uFCTadYRGrG2Avb\n BYsoRx0DnVvsv1FTrCf/rrVQ413agAgWqhv08zoz73Xo7QAik0eon8neG/KAjJH/Fayc\n Z3Wx+dHuW/+dglkk0uDeABF+DnQRFd4wYH21fZghLtpO05bZTAChGMEUGCGQhTs7lGsf\n cPww==","X-Gm-Message-State":"AOJu0YyDCCAecD5nK3WfENaAcPke8Pxafoy/FAvUsUIZQ2UO8tpK7OLd\n MEYfT3WQ3pNFIC/cpaIO8ygQotIseq6gEU5AOXo1G0i691hRNrvZAYKk3hHqp7O3yKllHYtMZOK\n YDoyG","X-Gm-Gg":"AeBDies+MOQesvqhWYGRgsWXR7hhpMzB3RpmEiufIYQdO9UO9GmgI5sBSrSsrrH6IaF\n 9wSf0V6Uped3vxj28VoGT3Kn+Og5DxHe3D+ULJHsRkBn+41FNfyb0cC2Gg6nzEmjwQscGP7u58V\n /E+UVWpDsJa+B7rLbozgNRK3HnG8nlQPxvgfb+3r4gltaLmiHWM4tex2oJGuSWo3AOp4WzbzKs9\n utlYztBi8dNaRrLMRJiHx+n9kZ9d6Gkwy88HF8vz6JOyWrMGW+qAvs+doEfh+mAOcfFKD3ANpYn\n jiZrk3fTgd0pfRcB6+VXVltSC3KGiJjkfest12W68t8gSokU3PlCX62pbM+Iu191gAr7sPJ1a5w\n GTag6ggbPxGv059uiq/xrxiJqCHykdZedXfuz3/RMCB9WoQBawbvujh6Idw9f9c+ts0S7tZsIbK\n 4b+BEQJtB9iQHu843xrEq+R6oAkmfjG+uvq4x+D86EiA3JddWsvg==","X-Received":"by 2002:a05:6a21:a341:b0:3a3:a6d8:cfea with SMTP id\n adf61e73a8af0-3a7f1d53b2bmr8007614637.8.1777993846044;\n Tue, 05 May 2026 08:10:46 -0700 (PDT)","From":"Waffl3x <waffl3x@baylibre.com>","To":"gcc-patches@gcc.gnu.org","Cc":"Waffl3x <waffl3x@baylibre.com>","Subject":"[PATCH 10/12] OpenMP/C++: Sorry for static vars in implicit constexpr\n functions","Date":"Tue,  5 May 2026 09:02:03 -0600","Message-ID":"<20260505151030.1749548-11-waffl3x@baylibre.com>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260505151030.1749548-1-waffl3x@baylibre.com>","References":"\n <CAH+W3Ppbho4pj6W-rWk4mMssrttOjt7aNco-oWW5Sw5f5Yx2GA@mail.gmail.com>\n <20260505151030.1749548-1-waffl3x@baylibre.com>","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>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"This patch disables use of static variables in an 'omp allocate' directive\ninside implicit constexpr functions. In such functions, the front end rushes\nto emit RTL for static variables via 'make_rtl_for_nonlocal_decl' prior\nto having even seen the allocate directive, meaning there is no clear\nmechanism for how to solve this. There is a lot of history to why it is\ndone this way, but it is clear that it is not the correct mechanism, which\nis a known issue. Unfortunately, the required redesign is rather\nsubstantial, and outside the scope of this patchset. This issue impacts\nC++17 lambdas and inline functions with '-fimplicit-constexpr'.\n\nIt can be kludged to work in templates, but since this would be\ninconsistent behavior, it's best to omit the surprises and rather\njust sorry, which is what we do here.\n\ngcc/cp/ChangeLog:\n\n\t* semantics.cc (finish_omp_allocate): Add sorry.\n\ngcc/testsuite/ChangeLog:\n\n\t* g++.dg/gomp/allocate-16.C: Remove xfails, check for sorry, modify\n\tcases impacted by sorry.\n\t* g++.dg/gomp/allocate-20.C: New test.\n\t* g++.dg/gomp/allocate-21.C: New test.\n\nSigned-off-by: Waffl3x <waffl3x@baylibre.com>\n---\n gcc/cp/semantics.cc                     | 22 ++++++\n gcc/testsuite/g++.dg/gomp/allocate-16.C | 55 +++++++++-----\n gcc/testsuite/g++.dg/gomp/allocate-20.C | 96 +++++++++++++++++++++++++\n gcc/testsuite/g++.dg/gomp/allocate-21.C | 88 +++++++++++++++++++++++\n 4 files changed, 243 insertions(+), 18 deletions(-)\n create mode 100644 gcc/testsuite/g++.dg/gomp/allocate-20.C\n create mode 100644 gcc/testsuite/g++.dg/gomp/allocate-21.C","diff":"diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc\nindex 00c09e119c8..c4a0a814318 100644\n--- a/gcc/cp/semantics.cc\n+++ b/gcc/cp/semantics.cc\n@@ -12432,6 +12432,28 @@ finish_omp_allocate (const location_t loc, const tree var_list,\n      still need access to them when diagnosing the allocator clause.  */\n   hash_set<tree> deferred_erroneous_var_nodes;\n \n+  /* Due to a workaround for static local variables in implicit constexpr\n+     functions, this case does not work properly.  */\n+  if (any_static_vars\n+      && DECL_DECLARES_FUNCTION_P (context)\n+      && maybe_constexpr_fn (context))\n+    {\n+      auto_diagnostic_group d;\n+      sorry_at (loc, \"static variables are not supported in an %<allocate%> \"\n+\t\t     \"directive in an implicit constexpr function\");\n+      emit_diag_for_var_group (tree_static_p,\n+\t\t\t       &inform,\n+\t\t\t       G_(\"static variables appear in the \"\n+\t\t\t\t  \"%<allocate%> directive here\"),\n+\t\t\t       var_list);\n+      for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))\n+\t{\n+\t  if (!tree_static_p (TREE_PURPOSE (vn)))\n+\t    continue;\n+\t  deferred_erroneous_var_nodes.add (vn);\n+\t}\n+    }\n+\n   const auto ref_var_p\n     = [] (const_tree t) -> bool { return TYPE_REF_P (TREE_TYPE (t)); };\n   if (any_of_vars (ref_var_p))\ndiff --git a/gcc/testsuite/g++.dg/gomp/allocate-16.C b/gcc/testsuite/g++.dg/gomp/allocate-16.C\nindex 7258d8c1c3c..12d2d763596 100644\n--- a/gcc/testsuite/g++.dg/gomp/allocate-16.C\n+++ b/gcc/testsuite/g++.dg/gomp/allocate-16.C\n@@ -1,5 +1,4 @@\n /* { dg-do compile { target c++11 } } */\n-/* { dg-ice \"\" { c++17 } } */\n #include \"allocate-allocator-handle.h\"\n \n /* Incorrect use of lambda captures in a directive or clause.\n@@ -53,6 +52,8 @@ void capture_used_in_allocator_clause_static_var()\n     /* { dg-error \"the value of 'alloc' is not usable in a constant expression\" \"\" { target *-*-* } .-1 } */\n     /* { dg-error \"'allocator' clause requires a constant predefined allocator\" \"\" { target *-*-* } .-2 } */\n     /* { dg-note \"because one or more variables with static storage duration appear in the 'allocate' directive\" \"\" { target *-*-* } .-3 } */\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-4 } */\n+    /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target c++17 } .-5 } */\n   };\n }\n \n@@ -61,14 +62,16 @@ void capture_used_in_allocator_clause_static_var_templ_uninstantiated()\n {\n   omp_allocator_handle_t alloc = omp_default_mem_alloc; /* { dg-note \"'omp_allocator_handle_t alloc' is not const\" \"\" { xfail *-*-* } } */\n   auto cl = [alloc](){\n-    static int a = 42; /* { dg-note \"'a' declared here\" \"\" { xfail *-*-* } } */\n+    static int a = 42; /* { dg-note \"'a' declared here\" \"\" { xfail c++14_down } } */\n     int b = 42;\t       /* { dg-bogus \"'b' declared here\" } */\n-    static int c = 42; /* { dg-note \"'c' declared here\" \"\" { xfail *-*-* } } */\n+    static int c = 42; /* { dg-note \"'c' declared here\" \"\" { xfail c++14_down } } */\n     int d = 42;        /* { dg-bogus \"'d' declared here\" } */\n     #pragma omp allocate(a, b, c, d) allocator(alloc)\n     /* { dg-error \"the value of 'alloc' is not usable in a constant expression\" \"\" { xfail *-*-* } .-1 } */\n     /* { dg-error \"'allocator' clause requires a constant predefined allocator\" \"\" { xfail *-*-* } .-2 } */\n     /* { dg-note \"because one or more variables with static storage duration appear in the 'allocate' directive\" \"\" { xfail *-*-* } .-3 } */\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-4 } */\n+    /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target c++17 } .-5 } */\n   };\n }\n /* This case can't be diagnosed, there exists a T where alloc is a converted\n@@ -79,11 +82,17 @@ void dependent_capture_used_in_allocator_clause_static_var_templ_uninstantiated(\n {\n   T alloc = omp_default_mem_alloc; /* { dg-bogus \"\" } */\n   auto cl = [alloc](){\n-    static int a = 42; /* { dg-bogus \"'a' declared here\" } */\n-    static int c = 42; /* { dg-bogus \"'c' declared here\" } */\n-    #pragma omp allocate(a, c) allocator(alloc)\n+    static int a = 42; /* { dg-bogus \"'a' declared here\" \"\" { target c++14_down } } */\n+    /* { dg-note \"'a' declared here\" \"\" { target c++17 } .-1 } */\n+    int b = 42;\t       /* { dg-bogus \"'b' declared here\" } */\n+    static int c = 42; /* { dg-bogus \"'c' declared here\" \"\" { target c++14_down } } */\n+    /* { dg-note \"'c' declared here\" \"\" { target c++17 } .-1 } */\n+    int d = 42;\t       /* { dg-bogus \"'d' declared here\" } */\n+    #pragma omp allocate(a, b, c, d) allocator(alloc)\n     /* { dg-bogus \"the value of 'alloc' is not usable in a constant expression\" \"\" { target *-*-* } .-1 } */\n     /* { dg-bogus \"because one or more variables with static storage duration appear in the 'allocate' directive\" \"\" { target *-*-* } .-2 } */\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-3 } */\n+    /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target c++17 } .-4 } */\n   };\n }\n \n@@ -92,14 +101,16 @@ void capture_used_in_allocator_clause_static_var_templ()\n {\n   omp_allocator_handle_t alloc = omp_default_mem_alloc; /* { dg-note \"'omp_allocator_handle_t alloc' is not const\" \"\" { xfail c++17 } } */\n   auto cl = [alloc](){\n-    static int a = 42; /* { dg-note \"'a' declared here\" \"\" { xfail c++17 } } */\n+    static int a = 42; /* { dg-note \"'a' declared here\" } */\n     int b = 42;\t       /* { dg-bogus \"'b' declared here\" } */\n-    static int c = 42; /* { dg-note \"'c' declared here\" \"\" { xfail c++17 } } */\n+    static int c = 42; /* { dg-note \"'c' declared here\" } */\n     int d = 42;        /* { dg-bogus \"'d' declared here\" } */\n     #pragma omp allocate(a, b, c, d) allocator(alloc)\n     /* { dg-error \"the value of 'alloc' is not usable in a constant expression\" \"\" { xfail c++17 } .-1 }*/\n     /* { dg-error \"'allocator' clause requires a constant predefined allocator\" \"\" { xfail c++17 } .-2 } */\n     /* { dg-note \"because one or more variables with static storage duration appear in the 'allocate' directive\" \"\" { xfail c++17 } .-3 } */\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-4 } */\n+    /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target c++17 } .-5 } */\n   };\n }\n \n@@ -108,14 +119,16 @@ void dependent_capture_used_in_allocator_clause_static_var_templ()\n {\n   T alloc = omp_default_mem_alloc; /* { dg-note \"'omp_allocator_handle_t alloc' is not const\" \"\" { xfail c++17 } } */\n   auto cl = [alloc](){\n-    static int a = 42; /* { dg-note \"'a' declared here\" \"\" { xfail c++17 } } */\n+    static int a = 42; /* { dg-note \"'a' declared here\" } */\n     int b = 42;\t       /* { dg-bogus \"'b' declared here\" } */\n-    static int c = 42; /* { dg-note \"'c' declared here\" \"\" { xfail c++17 } } */\n+    static int c = 42; /* { dg-note \"'c' declared here\" } */\n     int d = 42;        /* { dg-bogus \"'d' declared here\" } */\n     #pragma omp allocate(a, b, c, d) allocator(alloc)\n     /* { dg-error \"the value of 'alloc' is not usable in a constant expression\" \"\" { xfail c++17 } .-1 } */\n     /* { dg-error \"'allocator' clause requires a constant predefined allocator\" \"\" { xfail c++17 } .-2 } */\n     /* { dg-note \"because one or more variables with static storage duration appear in the 'allocate' directive\" \"\" { xfail c++17 } .-3 } */\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-4 } */\n+    /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target c++17 } .-5 } */\n   };\n }\n \n@@ -124,11 +137,17 @@ void dependent_capture_used_in_allocator_clause_static_var_templ_valid()\n {\n   T alloc = omp_default_mem_alloc; /* { dg-bogus \"\" } */\n   auto cl = [alloc](){\n-    static int a = 42; /* { dg-bogus \"\" } */\n-    static int c = 42; /* { dg-bogus \"\" } */\n+    static int a = 42; /* { dg-bogus \"'a' declared here\" \"\" { target c++14_down } } */\n+    /* { dg-note \"'a' declared here\" \"\" { target c++17 } .-1 } */\n+    int b = 42;\t       /* { dg-bogus \"'b' declared here\" } */\n+    static int c = 42; /* { dg-bogus \"'c' declared here\" \"\" { target c++14_down } } */\n+    /* { dg-note \"'c' declared here\" \"\" { target c++17 } .-1 } */\n+    int d = 42;\t       /* { dg-bogus \"'d' declared here\" } */\n     #pragma omp allocate(a, c) allocator(alloc)\n     /* { dg-bogus \"the value of 'alloc' is not usable in a constant expression\" \"\" { target *-*-* } .-1 } */\n     /* { dg-bogus \"'allocator' clause requires a constant predefined allocator\" \"\" { target *-*-* } .-2 } */\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-3 } */\n+    /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target c++17 } .-4 } */\n   };\n }\n \n@@ -187,24 +206,24 @@ void dependent_capture_used_in_align_clause_templ_uninstantiated()\n template<typename>\n void capture_used_in_align_clause_templ()\n {\n-  int align = 32; /* { dg-note \"'int align' is not const\" \"\" { xfail c++17 } } */\n+  int align = 32; /* { dg-note \"'int align' is not const\" } */\n   auto cl = [align](){\n     int a;\n     #pragma omp allocate(a) align(align)\n-    /* { dg-error \"the value of 'align' is not usable in a constant expression\" \"\" { target *-*-* xfail c++17 } .-1 } */\n-    /* { dg-error \"'align' clause argument needs to be positive constant power of two integer expression\" \"\" { target *-*-* xfail c++17 } .-2 } */\n+    /* { dg-error \"the value of 'align' is not usable in a constant expression\" \"\" { target *-*-* } .-1 } */\n+    /* { dg-error \"'align' clause argument needs to be positive constant power of two integer expression\" \"\" { target *-*-* } .-2 } */\n   };\n }\n \n template<typename T>\n void dependent_capture_used_in_align_clause_templ()\n {\n-  T align = 32; /* { dg-note \"'int align' is not const\" \"\" { xfail c++17 } } */\n+  T align = 32; /* { dg-note \"'int align' is not const\" } */\n   auto cl = [align](){\n     int a;\n     #pragma omp allocate(a) align(align)\n-    /* { dg-error \"the value of 'align' is not usable in a constant expression\" \"\" { target *-*-* xfail c++17 } .-1 } */\n-    /* { dg-error \"'align' clause argument needs to be positive constant power of two integer expression\" \"\" { target *-*-* xfail c++17 } .-2 } */\n+    /* { dg-error \"the value of 'align' is not usable in a constant expression\" \"\" { target *-*-* } .-1 } */\n+    /* { dg-error \"'align' clause argument needs to be positive constant power of two integer expression\" \"\" { target *-*-* } .-2 } */\n   };\n }\n \ndiff --git a/gcc/testsuite/g++.dg/gomp/allocate-20.C b/gcc/testsuite/g++.dg/gomp/allocate-20.C\nnew file mode 100644\nindex 00000000000..d7eccf012fb\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/gomp/allocate-20.C\n@@ -0,0 +1,96 @@\n+/* { dg-do compile { target c++11 } } */\n+#include \"allocate-allocator-handle.h\"\n+\n+/* Diagnose static variables used in an OpenMP allocate directive in functions\n+   that are implicitly constexpr.\n+   Otherwise, check that static variables have a correct alignment applied to\n+   them.\n+\n+   This test case is valid in c++11 but the bug we are testing for does not\n+   manifest until c++17, which makes lambdas implicit constexpr functions.\n+   \n+   For now, we simply do not support these cases.  */\n+\n+\n+/* Making a regex for demangled identifiers is actually way harder than making\n+   a regex for mangled ones, too many escapes are needed.  */\n+\n+/* { dg-final { scan-assembler \"\\.align 256\\\\s*\\.type\\\\s*_ZZZ6f0_256vENKUlvE_clEvE1a\" { target c++14_down } } } */\n+int* f0_256()\n+{\n+  auto cl = [](){\n+    static int a = 42;\n+    #pragma omp allocate(a) align(256) allocator(omp_default_mem_alloc)\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-1 } */\n+    return &a;\n+  };\n+  return cl();\n+}\n+/* { dg-final { scan-assembler \"\\.align 512\\\\s*\\.type\\\\s*_ZZZ6f0_512vENKUlvE_clEvE1a\" { target c++14_down } } } */\n+int* f0_512()\n+{\n+  auto cl = [](){\n+    static int a = 42;\n+    #pragma omp allocate(a) align(512) allocator(omp_default_mem_alloc)\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-1 } */\n+    return &a;\n+  };\n+  return cl();\n+}\n+/* { dg-final { scan-assembler \"\\.align 1024\\\\s*\\.type\\\\s*_ZZZ7f0_1024vENKUlvE_clEvE1a\" { target c++14_down } } } */\n+int* f0_1024()\n+{\n+  auto cl = [](){\n+    static int a = 42;\n+    #pragma omp allocate(a) align(1024) allocator(omp_default_mem_alloc)\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-1 } */\n+    return &a;\n+  };\n+  return cl();\n+}\n+\n+/* { dg-final { scan-assembler \"\\.align 256\\\\s*\\.type\\\\s*_ZZZ6f1_256IvEPivENKUlvE_clEvE1a\" { target c++14_down } } } */\n+template<typename>\n+int* f1_256()\n+{\n+  auto cl = [](){\n+    static int a = 42;\n+    #pragma omp allocate(a) align(256) allocator(omp_default_mem_alloc)\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-1 } */\n+    return &a;\n+  };\n+  return cl();\n+}\n+template int* f1_256<void>();\n+\n+/* { dg-final { scan-assembler \"\\.align 512\\\\s*\\.type\\\\s*_ZZZ6f1_512IvEPivENKUlvE_clEvE1a\" { target c++14_down } } } */\n+template<typename>\n+int* f1_512()\n+{\n+  auto cl = [](){\n+    static int a = 42;\n+    #pragma omp allocate(a) align(512) allocator(omp_default_mem_alloc)\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-1 } */\n+    return &a;\n+  };\n+  return cl();\n+}\n+template int* f1_512<void>();\n+\n+/* { dg-final { scan-assembler \"\\.align 1024\\\\s*\\.type\\\\s*_ZZZ7f1_1024IvEPivENKUlvE_clEvE1a\" { target c++14_down } } } */\n+template<typename>\n+int* f1_1024()\n+{\n+  auto cl = [](){\n+    static int a = 42;\n+    #pragma omp allocate(a) align(1024) allocator(omp_default_mem_alloc)\n+    /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target c++17 } .-1 } */\n+    return &a;\n+  };\n+  return cl();\n+}\n+template int* f1_1024<void>();\n+\n+/* Missing cases for generic lambda, and generic lambda in function template.\n+   They shouldn't behave differently, but for completeness they should be\n+   added, I'm just not going to spend any more time on this right now.  */\ndiff --git a/gcc/testsuite/g++.dg/gomp/allocate-21.C b/gcc/testsuite/g++.dg/gomp/allocate-21.C\nnew file mode 100644\nindex 00000000000..7a638443f32\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/gomp/allocate-21.C\n@@ -0,0 +1,88 @@\n+/* { dg-do compile { target c++14 } } */\n+/* { dg-additional-options \"-fimplicit-constexpr\" } */\n+#include \"allocate-allocator-handle.h\"\n+\n+/* Diagnose static variables used in an OpenMP allocate directive in functions\n+   that are implicitly constexpr.\n+   Inline functions and function templates with -fimplicit-constexpr.\n+   \n+   For now, we simply do not support these cases.\n+   \n+   The dg-final cases are never checked, they are kept here for demonstrating\n+   intent and so they can be switched back on if these cases are fixed.  */\n+\n+/* Making a regex for demangled identifiers is actually way harder than making\n+   a regex for mangled ones, too many escapes are needed.\n+\n+   We need to ODR-use the regular functions to force them to be emitted.  */\n+\n+/* { dg-final { scan-assembler \"\\.align 256\\\\s*\\.type\\\\s*_ZZ6f0_256vE1a\" { target { ! *-*-* } } } } */\n+inline int* f0_256()\n+{\n+  static int a = 42; /* { dg-note \"'a' declared here\" } */\n+  #pragma omp allocate(a) align(256) allocator(omp_default_mem_alloc)\n+  /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target *-*-* } .-1 } */\n+  /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target *-*-* } .-2 } */\n+  return &a;\n+}\n+constexpr int*(*odr_use_f0_256)() = &f0_256;\n+\n+/* { dg-final { scan-assembler \"\\.align 512\\\\s*\\.type\\\\s*_ZZ6f0_512vE1a\" { target { ! *-*-* } } } } */\n+inline int* f0_512()\n+{\n+  static int a = 42; /* { dg-note \"'a' declared here\" } */\n+  #pragma omp allocate(a) align(512) allocator(omp_default_mem_alloc)\n+  /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target *-*-* } .-1 } */\n+  /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target *-*-* } .-2 } */\n+  return &a;\n+}\n+constexpr int*(*odr_use_f0_512)() = &f0_512;\n+\n+/* { dg-final { scan-assembler \"\\.align 1024\\\\s*\\.type\\\\s*_ZZ7f0_1024vE1a\" { target { ! *-*-* } } } } */\n+inline int* f0_1024()\n+{\n+  static int a = 42; /* { dg-note \"'a' declared here\" } */\n+  #pragma omp allocate(a) align(1024) allocator(omp_default_mem_alloc)\n+  /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target *-*-* } .-1 } */\n+  /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target *-*-* } .-2 } */\n+  return &a;\n+}\n+constexpr int*(*odr_use_f0_1024)() = &f0_1024;\n+\n+\n+\n+/* { dg-final { scan-assembler \"\\.align 256\\\\s*\\.type\\\\s*_ZZ6f1_256IvEPivE1a\" { target { ! *-*-* } } } } */\n+template<typename>\n+inline int* f1_256()\n+{\n+  static int a = 42; /* { dg-note \"'a' declared here\" } */\n+  #pragma omp allocate(a) align(256) allocator(omp_default_mem_alloc)\n+  /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target *-*-* } .-1 } */\n+  /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target *-*-* } .-2 } */\n+  return &a;\n+}\n+template int* f1_256<void>();\n+\n+/* { dg-final { scan-assembler \"\\.align 512\\\\s*\\.type\\\\s*_ZZ6f1_512IvEPivE1a\" { target { ! *-*-* } } } } */\n+template<typename>\n+inline int* f1_512()\n+{\n+  static int a = 42; /* { dg-note \"'a' declared here\" } */\n+  #pragma omp allocate(a) align(512) allocator(omp_default_mem_alloc)\n+  /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target *-*-* } .-1 } */\n+  /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target *-*-* } .-2 } */\n+  return &a;\n+}\n+template int* f1_512<void>();\n+\n+/* { dg-final { scan-assembler \"\\.align 1024\\\\s*\\.type\\\\s*_ZZ7f1_1024IvEPivE1a\" { target { ! *-*-* } } } } */\n+template<typename>\n+inline int* f1_1024()\n+{\n+  static int a = 42; /* { dg-note \"'a' declared here\" } */\n+  #pragma omp allocate(a) align(1024) allocator(omp_default_mem_alloc)\n+  /* { dg-message \"static variables are not supported in an 'allocate' directive in an implicit constexpr function\" \"\" { target *-*-* } .-1 } */\n+  /* { dg-note \"static variables appear in the 'allocate' directive here\" \"\" { target *-*-* } .-2 } */\n+  return &a;\n+}\n+template int* f1_1024<void>();\n","prefixes":["10/12"]}