From patchwork Sun Apr 30 02:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 88899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1900786vqo; Sat, 29 Apr 2023 19:02:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XAABBuZytTtrUBD55uktebNpSLMWregsjIrbJQgA4xVC8ZF8NV0CNQ69Z6Rz+uNKTploB X-Received: by 2002:aa7:dd10:0:b0:509:c669:1e93 with SMTP id i16-20020aa7dd10000000b00509c6691e93mr2350609edv.23.1682820126895; Sat, 29 Apr 2023 19:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682820126; cv=none; d=google.com; s=arc-20160816; b=Jd653HElFrf9ya9UdBCCz4TE0A5zZFt4WW8V0bAwWmC0CMaKCSGhiImJ89D59n8E4g J4JlHUQjf9ovXxN+hQXNFMWeBGoKHu2OSdGnvGY7aQTNdFyOXGWpytDa3vor+wGo/0RL sFyM050l3Ldd5fCmtZYhxqNgQ5E3UAT9ZI0Uz1fvnFCBw7JCX2LmdZq7uPmS7spwgkEa hribfZtX8t7Nv1GytsYPdkIY8+krXAysVaUmjY0NYTgTP1ztE9EwcX+KiRgMAifSeNrE lvcDx5UItNtgD4LdZ+13lyHTARQFokjMIYHhouZVkNMsE46W2ZC47XuxKSPOYa19yZLr 7BjA== 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 :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=pm0pR+81WfrSnJkKmXfE+iVe2mNiAuOkZntEXzw4Wgk=; b=0kLnSx0coEUohV/r1QPh0XuzIXJHByQO/WrTzCma1deUj8u8X2LSOtXjmaMDp8zWKt gI8r/o6KsPU9V3ZwlhbZ9mGLtsKBLtA5T0yaL649oIPqEfc+vVlznflZ7lk1oquaeqXg vDx3nqt2Luewd8/r2Iz9CIObs2JJmYSJU595a4M0/HTTR1M2Y9AouR3keryFwYUqzo7k WikIHPwXlK8ac/gMtNkB1jSaCrHkHXxH81kD3+We6V3jv//LLn8dqwE5W2cY8i01cKXv JJFHfEYjIsfdmgeldVT2kMTUCwVNWECaSZrV87TBYXWX7G9Ii8Ivb8Zln4LR/BebiGmu wesQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=g2LOiVBK; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n17-20020a056402061100b00506adeaaaf1si18028145edv.303.2023.04.29.19.02.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 19:02:06 -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=g2LOiVBK; 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 60D913858416 for ; Sun, 30 Apr 2023 02:02:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60D913858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682820125; bh=pm0pR+81WfrSnJkKmXfE+iVe2mNiAuOkZntEXzw4Wgk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=g2LOiVBKTbx2IG5blc2o+/yhfancWdXu0/Cu0H1qBDu75UZ/6Ne5Vqgy+IRMezU2c 6+647gbe/A1tALwy9L6ZQr/WQ6ipo5THJnENTR2JQSZY0dpVvwmzgCo6GsVDiSbG3T Qge8AenHk/fwq+QYlEf6d8Tr9bdHaBWazOHW9phg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 4FDC43858D28 for ; Sun, 30 Apr 2023 02:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FDC43858D28 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1a68f2345c5so9991105ad.2 for ; Sat, 29 Apr 2023 19:00:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682820012; x=1685412012; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pm0pR+81WfrSnJkKmXfE+iVe2mNiAuOkZntEXzw4Wgk=; b=kS5WPYnHKiuaWEopY50ZMYf1gqSqCTMgQEy/3/+z3lVuHdBNpeQ5rOx1OtAnskOlxg ZFKQFGUAHPFUfgrt/SNVWRUNXSy2FFLDwP3XMFA4RJoqcFIbmYPabLwct0MrLZuuLS+c 29kGex6wC2cxHknnI0e9VDGei+RFAo1WqdeCz9IEFnyFEdKg6NZD0gfxfXs2CGgoN08V jq0+EaIzG12d5y2ys3BvefmFQ5yD0xIL2IMqXvc7ldQoWR4688MuWwumbv9aIkmJrzYi rkAGRG5HRbgy+QPrpILyBwBfmI4f8+O8agRnbGPtS5Z+VhEXc46oF1s5OANw1G0owp8h TK8g== X-Gm-Message-State: AC+VfDxLUOF8/rZCD0VNVZP0pL+K0hTSAUatDADhcykdmC5nGqGyEiSO a81ZTRNddq/YjMlxL3v6+Cf1w82tq88= X-Received: by 2002:a17:902:aa92:b0:1a1:bede:5e54 with SMTP id d18-20020a170902aa9200b001a1bede5e54mr9622957plr.59.1682820011608; Sat, 29 Apr 2023 19:00:11 -0700 (PDT) Received: from Thaum.localdomain (125-209-144-50.tpgi.com.au. [125.209.144.50]) by smtp.gmail.com with ESMTPSA id x12-20020a1709027c0c00b001a52e3e3745sm15350426pll.296.2023.04.29.19.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 19:00:11 -0700 (PDT) Date: Sun, 30 Apr 2023 12:00:05 +1000 To: gcc-patches@gcc.gnu.org Cc: Nathaniel Shead Subject: [PATCH] c++: Report invalid id-expression in decltype [PR100482] Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764564797380242481?= X-GMAIL-MSGID: =?utf-8?q?1764564797380242481?= 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 100482 gcc/cp/ChangeLog: * parser.cc (cp_parser_decltype_expr): Report errors raised by finish_id_expression. gcc/testsuite/ChangeLog: * g++.dg/pr100482.C: New test. Signed-off-by: Nathaniel Shead Signed-off-by: Nathaniel Shead --- gcc/cp/parser.cc | 22 +++++++++++----------- gcc/testsuite/g++.dg/pr100482.C | 11 +++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr100482.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index e5f032f2330..20ebcdc3cfd 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/pr100482.C b/gcc/testsuite/g++.dg/pr100482.C new file mode 100644 index 00000000000..dcf6722fda5 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr100482.C @@ -0,0 +1,11 @@ +// { 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" }