From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 60EBB3857829 for ; Tue, 5 Apr 2022 16:26:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 60EBB3857829 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-151-OLm7nsTTNrmOAxWFy2sKaw-1; Tue, 05 Apr 2022 12:26:56 -0400 X-MC-Unique: OLm7nsTTNrmOAxWFy2sKaw-1 Received: by mail-qv1-f69.google.com with SMTP id kj4-20020a056214528400b0044399a9bb4cso11526043qvb.15 for ; Tue, 05 Apr 2022 09:26:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=WRk9c5f6b6AaH/V6B/Klp+6fz9CFS3rbAy/OWe7vmMA=; b=tg48Vyv8dyOOuU75vOzqMunSQpI8YBDvyO33wk2aKWvyvbxTqBBaFXG3WQYTDPsy8w oHnHZzpGnv0NkOvTIQa27U2YWIqhdvpyFr1KpyyjAdmJTp3yG5uUnBU5DbRhy7wtnZg9 40vu304gqLOwGx34q3iSBQrMf0ZzDvPD4nJjsz8liJJ2HuyAqK5XZsFEBcerXVQzL3AZ TvzBM41mjwnonZEwFPWHymvEdvt3OyFm0X0ZcyklJyZEvrgYzWETaYlG2d7ZiOAJxShC o5QafE85qK9vE+1mXfqNydGmNkachLD4Hi7xh8u8vrBbs6RlxuR+N912B67OoOowxyYQ MEgQ== X-Gm-Message-State: AOAM531jc40DqPmcM5JK7PZ26sZLgdjAxUd45roFMaTlz/3P+0RIJwST TE9w5SS4pzJH8cvFacEpJUnyDX3a7bMXpO7SOHXouDNKG6iY3+S9HvBYEcRsMJbLBrsWeyUvCVm GgqbAVZJDNuo31RhDWocKNOx0qaZZFrPwi1sRcqrutxaEwOjAK+j0YmvT+gLhgAKEww== X-Received: by 2002:a05:6214:d05:b0:441:527b:2148 with SMTP id 5-20020a0562140d0500b00441527b2148mr3364976qvh.0.1649176015551; Tue, 05 Apr 2022 09:26:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxeyj62b2c4indidBs9qdtwjPx162XNSdOdNAfPoIgs6ZIht19E4D/sNcW03H6MjCLjYPoIA== X-Received: by 2002:a05:6214:d05:b0:441:527b:2148 with SMTP id 5-20020a0562140d0500b00441527b2148mr3364951qvh.0.1649176015088; Tue, 05 Apr 2022 09:26:55 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id c3-20020ac87d83000000b002e1d1b3df15sm11567034qtd.44.2022.04.05.09.26.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 09:26:54 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: elaborated-type-spec in requires-expr [PR101677] Date: Tue, 5 Apr 2022 12:26:39 -0400 Message-Id: <20220405162639.2098812-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Tue, 05 Apr 2022 16:26:59 -0000 We were failing to declare class S in the global namespace because we were treating the requires-expression parameter scope as a normal block scope, so the implicit declaration went there. It seems to me that the requires parameter scope is more like a function parameter scope (not least in the use of the word "parameter"), so let's change the scope kind. But then we need to adjust the prohibition on placeholders declaring implicit template parameters. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/101677 gcc/cp/ChangeLog: * name-lookup.h (struct cp_binding_level): Add requires_expression bit-field. * name-lookup.cc (pushtag): Check it. * parser.cc (cp_parser_requires_expression): Set it. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires28.C: New test. --- gcc/cp/name-lookup.h | 5 ++++- gcc/cp/parser.cc | 5 +++-- gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C | 13 +++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 68d08725a00..fa039028847 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -309,7 +309,10 @@ struct GTY(()) cp_binding_level { /* true for SK_FUNCTION_PARMS of immediate functions. */ unsigned immediate_fn_ctx_p : 1; - /* 22 bits left to fill a 32-bit word. */ + /* True for SK_FUNCTION_PARMS of a requires-expression. */ + unsigned requires_expression: 1; + + /* 21 bits left to fill a 32-bit word. */ }; /* The binding level currently in effect. */ diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 7e1c777364e..bfd16e1ef62 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -29964,7 +29964,8 @@ cp_parser_requires_expression (cp_parser *parser) scope_sentinel () { ++cp_unevaluated_operand; - begin_scope (sk_block, NULL_TREE); + begin_scope (sk_function_parms, NULL_TREE); + current_binding_level->requires_expression = true; } ~scope_sentinel () @@ -48082,7 +48083,7 @@ static tree synthesize_implicit_template_parm (cp_parser *parser, tree constr) { /* A requires-clause is not a function and cannot have placeholders. */ - if (current_binding_level->kind == sk_block) + if (current_binding_level->requires_expression) { error ("placeholder type not allowed in this context"); return error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C index c74f6f00a5c..bdd5f9699e0 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C @@ -12,7 +12,7 @@ concept C0 = requires (auto x) { // { dg-error "placeholder type" } template concept C1 = requires (C1 auto x) { // { dg-error "not been declared|placeholder|two or more|in requirements" } x; // { dg-error "not declared" } - { x } -> c; // { dg-message "is invalid" } + { x } -> c; // { dg-message "is invalid|not declared" } }; template diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C new file mode 100644 index 00000000000..e632f0167f4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C @@ -0,0 +1,13 @@ +// PR c++/101677 +// { dg-do compile { target c++20 } } + +template +concept C_bug_with_forward_decl = requires(T& t){ + t.template f(); +}; + +struct good { + template void f() {} +}; + +static_assert(C_bug_with_forward_decl); base-commit: 5c8d22b00adedc21f8b697dd6b990f4821a06634 -- 2.27.0