From patchwork Fri Sep 11 20:54:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1362685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rhFImeJg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bp7LN1cdPz9sTg for ; Sat, 12 Sep 2020 06:55:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D873386F019; Fri, 11 Sep 2020 20:55:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by sourceware.org (Postfix) with ESMTPS id F1B143857039 for ; Fri, 11 Sep 2020 20:55:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F1B143857039 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf30.google.com with SMTP id p15so5366977qvk.5 for ; Fri, 11 Sep 2020 13:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=1XBLpY7r30bP5F7kFexpE9zcWn3p6DPDfbLi52lRsKc=; b=rhFImeJg4vX3LGx3W+bs8TMYaHqOXlHOjr3vHR3b5+2I5HObbPklk4mJP4eOFOCBMr qcUjEDStl+H1ARn16bEshe9umwLcPhnoV3QSD6Bnkp0WjBri68Ayxbrh9XIkrdW5B27N /xr8Plh89ipqhjQxMQWYu5tUl33uK+DtCPOvFci38CoSEO93TnJjWPzYagsWWLKLP033 rUVpKUwSdRJVjbBpn3MgIHZ/JWYrMkGJMc3NEn416WeNBovMrW2cHn0mQtv8Cok6C32F 6LhMMq7zC3iZ+Xzh5MtVDDCtyvyZw2XNeVBfKx/pf45na+TbS+B3XA+UAGoTs4HUoT/J 26Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=1XBLpY7r30bP5F7kFexpE9zcWn3p6DPDfbLi52lRsKc=; b=OF6VDdYFLlkEteaQo0kkxO2N2RF7zrfbP6dYRVCsTFmyhr+y7aMvhy99JArlhxGInu oq/zVHzAtwfo47cR7ZiXjnYuaoZh+GeZArh0yiAGneSSvhLcY4dDvGmBjl64MnjKKYiT 94Ej72MVRl8jNnaloNF2II74JQBUTzHALfzyU5chSc4NYTEMA/ApwxDIhYm7Raf4qFDW y9jVqo7FmB7knV/hzGhsFY7jryNZDsVEfl8IpyLTeRbzHc/fgHRx6XKrLWu93Mn3tKEm 6Mm7u9fy9OxAV7khvsA5Ad5kQVm96X+1YbfKg9l4VDGUOXJnZF4gIP6sqDT9M44hOg1n J6Ew== X-Gm-Message-State: AOAM533WZVO2FKGvvy6JWM+fhVQSMcg9GN5+tDgyM5qysBdammMZhgUJ fSwwazGChXdX8OcLuWLehjk= X-Google-Smtp-Source: ABdhPJzjI4JY9ziR1AWIEY+9bcWkXl5sxf7wARm7C1K97MYilNq/kZwioFYFpTNN0NpEmo3JtFJ70Q== X-Received: by 2002:a0c:9ac9:: with SMTP id k9mr3951537qvf.19.1599857699922; Fri, 11 Sep 2020 13:54:59 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:f526:facd:40a1:322d? ([2620:10d:c091:480::1:2df1]) by smtp.googlemail.com with ESMTPSA id e1sm4209784qtb.0.2020.09.11.13.54.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Sep 2020 13:54:59 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Concepts and local externs Message-ID: <8ff3d8d9-29b3-7494-f367-7197aa352a16@acm.org> Date: Fri, 11 Sep 2020 16:54:58 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I discovered that we'd accept constraints on block-scope function decls inside templates. This fixes that. gcc/cp/ * decl.c (grokfndecl): Don't attach to local extern. gcc/testsuite/ * concepts/local-extern.C: New. pushed to trunk nathan diff --git c/gcc/cp/decl.c w/gcc/cp/decl.c index 8922ef54d74..ad2a30fcf71 100644 --- c/gcc/cp/decl.c +++ w/gcc/cp/decl.c @@ -9457,7 +9457,10 @@ grokfndecl (tree ctype, { tree tmpl_reqs = NULL_TREE; tree ctx = friendp ? current_class_type : ctype; - bool memtmpl = (processing_template_decl > template_class_depth (ctx)); + bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL; + bool memtmpl = (!block_local + && (processing_template_decl + > template_class_depth (ctx))); if (memtmpl) tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); tree ci = build_constraints (tmpl_reqs, decl_reqs); @@ -9467,9 +9470,11 @@ grokfndecl (tree ctype, ci = NULL_TREE; } /* C++20 CA378: Remove non-templated constrained functions. */ - if (ci && !flag_concepts_ts - && (!processing_template_decl - || (friendp && !memtmpl && !funcdef_flag))) + if (ci + && (block_local + || (!flag_concepts_ts + && (!processing_template_decl + || (friendp && !memtmpl && !funcdef_flag))))) { error_at (location, "constraints on a non-templated function"); ci = NULL_TREE; diff --git c/gcc/testsuite/g++.dg/concepts/local-extern.C w/gcc/testsuite/g++.dg/concepts/local-extern.C new file mode 100644 index 00000000000..69ecc2361c0 --- /dev/null +++ w/gcc/testsuite/g++.dg/concepts/local-extern.C @@ -0,0 +1,39 @@ +// { dg-do compile { target c++17 } } +// { dg-additional-options -fconcepts } + +// Don't attach constraints to block-scope fn-decls and ICE + +template + concept input_or_output_iterator + = requires(_Iter __i) { { *__i } ; }; + + + template + class common_iterator + { + + public: + +void + frob () + { + if (__builtin_is_constant_evaluated()) + { + void __failed_assertion(); // ICEd + if (!bool(_M_index == 0)) __failed_assertion(); + } + + } + + private: + unsigned char _M_index; + }; + +template concept C = true; + +template +void F () +{ + void bad () requires C; // { dg-error "a non-templated function" } + +}