From patchwork Tue Aug 8 02:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 132488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1837694vqr; Mon, 7 Aug 2023 19:41:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRJMp9PO/Q4jJU2/wOu59/HfPmsn9vSA2cy8UUsjnULF2wzLFdFGHYfwEC91KjQ7uTPOCk X-Received: by 2002:aa7:d1d7:0:b0:522:29d3:4185 with SMTP id g23-20020aa7d1d7000000b0052229d34185mr9546094edp.32.1691462468372; Mon, 07 Aug 2023 19:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691462468; cv=none; d=google.com; s=arc-20160816; b=p0S8VI1IxzY0pi6/eJjCQIzvX77JOkfSEQn53hDiSuqxV6WditBaYj0THm20D7OTev zwvOGI9Rp4PdoFh9fqNFVx/H5FQ2BnZHNM5iq+nloW+DQ24Gu5nSi3jBRTLDrmGxOnET dWJicXtj1JFCci2c9aD6w9KmqaKZ0zbuWOYYpXVQDnWJ10lc3fFOQOx5mUiun78yyd8o xOB/j3BFEdHfNjcjqFWKVm3JcHrBmIr1yIIXtvmdv9jtLniCrESaFXLG7Tbjjxqe3qSI ufmPP8wIlcwAeoR5fui/3y+hEqxFj080N6FrQfcfqUsow1Ph2CgUtSK1MYDrpKBDbUdM cmTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=FofxZfEcnYFF8qi9IDSPi3eqorZOze3Uxp0gFEzSKTs=; fh=dKYAqBRQc5As17VcTBVmpEqV2XcO6vNkRJVM8xaHGUE=; b=OlkQiHGtHTyQsCBXGf9eV/3PfffwSfPTZPT4FL4r5OVjqOInpobkYuxWBqWO7yPt1S XMo2xFkgDqe9288oZQzvvIN/Q/NiXLUaAlfurjct7xOp0c0VoPhBKguE9LP58/asnZeN quH3Iy8EiziYcvgvuhz8BmQx+vrqt1hAvvrVu2Xru3efK09e1balyvdWox1k2L6/f3U4 h7YU00Z72vVnfRozVeCSrQFAld6TbAZ6Y6OLV0/JPJ4t3iCrExH92OnMCA1KeMwbo5Zk jZ8aEiWB0drkrr8GM+juxL861Pih8qP+35800paEGrsLj4g8n2q+hNvj7eNH3CamH4yU QztQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hGayBfVA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m19-20020a50ef13000000b00522b7f30c36si6902577eds.81.2023.08.07.19.41.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 19:41:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hGayBfVA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 133D33858284 for ; Tue, 8 Aug 2023 02:41:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 133D33858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691462467; bh=FofxZfEcnYFF8qi9IDSPi3eqorZOze3Uxp0gFEzSKTs=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hGayBfVA0epPsB4vqDtJZ1nN0Jurn6Dsi+gWMFdhpWIRtfAYIh7qOiVFeSDt8pAcV bHba6xpKsPNvoJle74TSDU95W0Rb4jK8q7FROjB1L2CsEiawW+NNjUSAOOMKOwZqtF g9yUnPc2F19sspKmOAIvRoXMjgQMScC103+3Cjpc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 5E5633858C41 for ; Tue, 8 Aug 2023 02:40:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E5633858C41 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-267fabc8465so2871552a91.1 for ; Mon, 07 Aug 2023 19:40:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691462423; x=1692067223; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FofxZfEcnYFF8qi9IDSPi3eqorZOze3Uxp0gFEzSKTs=; b=iP0dpZRTZuHVoffgUW0iGXBGXxr5gV2caH3RYhCFvrXhriTjhvoMJV4PymdadOS3G0 sUt2mMw5iwYlppcAv1FoWJ42q4Q8TTuPn1+6T2rweXoKm0S/72qoTIl8leFII5aSEo3S QbJN7rNcLbGmODXwRxN2kAHX8Il7MQdDEGTrParYBjNyc4hNcsDlWqR8X4F60nTbkF7y gll1K3d2uH/vtF61cqw7Z5HVy7/1UorAh0wpsuglegbhad31W41SxVNSleEdmkWGmW8Y qPEkHGQP/G74voQuCGhGtd1rhn2nr4PrIB9Dow1D7k6mc7IoNsbXd6GzXEfYjg2om2Q1 5coA== X-Gm-Message-State: AOJu0YzkZRzGbUlntlIMRBXWhSR6eHIaozZt7Uq6LsBhld3s8WmFMlkH KgYohG4GI43CGv0Xvd8JF+W9YqKocc0= X-Received: by 2002:a17:90a:688e:b0:268:1d18:a19f with SMTP id a14-20020a17090a688e00b002681d18a19fmr9107076pjd.25.1691462423020; Mon, 07 Aug 2023 19:40:23 -0700 (PDT) Received: from Thaum.localdomain (59-102-120-25.tpgi.com.au. [59.102.120.25]) by smtp.gmail.com with ESMTPSA id i4-20020a17090a64c400b0026307fa0442sm9266288pjm.49.2023.08.07.19.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 19:40:22 -0700 (PDT) Date: Tue, 8 Aug 2023 12:40:17 +1000 To: gcc-patches@gcc.gnu.org Cc: Patrick Palka , Jason Merrill Subject: [PATCH] c++: Report invalid id-expression in decltype [PR100482] Message-ID: References: <4cd26c62-2ecf-db54-f180-9fe4be282449@idea> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Nathaniel Shead via Gcc-patches From: Nathaniel Shead Reply-To: Nathaniel Shead Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1764564797380242481 X-GMAIL-MSGID: 1773626949429709081 Ping for https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622681.html. -- 8< -- This patch ensures that any errors raised by finish_id_expression when parsing a decltype expression are properly reported, rather than potentially going ignored and causing invalid code to be accepted. We can also now remove the separate check for templates without args as this is also checked for in finish_id_expression. PR c++/100482 gcc/cp/ChangeLog: * parser.cc (cp_parser_decltype_expr): Report errors raised by finish_id_expression. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/decltype-100482.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/parser.cc | 22 ++++++++++---------- gcc/testsuite/g++.dg/cpp0x/decltype-100482.C | 12 +++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype-100482.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index dd3665c8ccf..990f2034f54 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -16508,10 +16508,6 @@ cp_parser_decltype_expr (cp_parser *parser, expr = cp_parser_lookup_name_simple (parser, expr, id_expr_start_token->location); - if (expr && TREE_CODE (expr) == TEMPLATE_DECL) - /* A template without args is not a complete id-expression. */ - expr = error_mark_node; - if (expr && expr != error_mark_node && TREE_CODE (expr) != TYPE_DECL @@ -16532,13 +16528,17 @@ cp_parser_decltype_expr (cp_parser *parser, &error_msg, id_expr_start_token->location)); - if (expr == error_mark_node) - /* We found an id-expression, but it was something that we - should not have found. This is an error, not something - we can recover from, so note that we found an - id-expression and we'll recover as gracefully as - possible. */ - id_expression_or_member_access_p = true; + if (error_msg) + { + /* We found an id-expression, but it was something that we + should not have found. This is an error, not something + we can recover from, so report the error we found and + we'll recover as gracefully as possible. */ + cp_parser_parse_definitely (parser); + cp_parser_error (parser, error_msg); + id_expression_or_member_access_p = true; + return error_mark_node; + } } if (expr diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-100482.C b/gcc/testsuite/g++.dg/cpp0x/decltype-100482.C new file mode 100644 index 00000000000..3df9c8496d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/decltype-100482.C @@ -0,0 +1,12 @@ +// PR c++/100482 +// { dg-do compile { target c++11 } } + +namespace N {} +decltype(std) x; // { dg-error "expected primary-expression" } + +struct S {}; +decltype(S) y; // { dg-error "argument to .decltype. must be an expression" } + +template +struct U {}; +decltype(U) z; // { dg-error "missing template arguments" }