From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id F1E5D3858D33 for ; Tue, 8 Aug 2023 02:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1E5D3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2680a031283so2941260a91.3 for ; Mon, 07 Aug 2023 19:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691462929; x=1692067729; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KkVynM5hDWOkGkh2ClZ4a1jWSXzJuQjzYMAKOZyrtSw=; b=hfs5IyXsiVGiKWEMpiuZ/bWIyFMRdDi9ik0Ola53iM9RtxcUrW+DsR94CN7cG30JER yL8/8xwdE1PpKVWjnozkGf6hu3uyFcwSStncINxzGh5hBEQllzIE3UPCFzX5tZXL7nMX Olxemfd14aRJGwBh4vLU3JomN/oFDZeccaIssr7uP6wwyO+Jv3NPKQzu0BgzYNvVZmXz zjPCkZRzzl1Ojc8RKE1dbtMfdqLZNOmDH6XsvIrifI3H4n4KruAEbVeYXz6RlMoUlNOd PJE2JVmMoLPiuetH0nBUiu3yFiRA92oXsUUWIXqBfCB5vWGgztFYtPlsttkJAQWi9hao 9VCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691462929; x=1692067729; 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=KkVynM5hDWOkGkh2ClZ4a1jWSXzJuQjzYMAKOZyrtSw=; b=LIYAVpr2YBfbaANHlq5TL9o4lxzEnH+m2mYJAtRs144EU3YCjDZAK5XyRKRhQWeeK7 UMQ9SMgDAZ6KSfPaXrLGrT190JjJghdJJeBznxQ6iPSwW89VZ1g+hlB5QjiO5r59s0hN erymi7H7+Mo8m6jnFQofmA3LhkeETYHHT+HPF8MW/yvpXh3meklXZ4363i9abHa/Hh7r uYv3veFR1mR5gRYJSvSzUF/G9L46271dAjfqyJMAo6zPTFc/6zx9VzlMeqQx5Qoc3/hY Fma2PSPGTV9QL5kNgIbiqr8HbcrWrcT+hGJUJth/zk8D2XWdD01nNzg/J1O3MdcNzwwP u7Kg== X-Gm-Message-State: AOJu0YxvyBz6W0+dYgJU8PTUuXFiwF41dBjwmD/B8JVk2oQp6ZTv44si QVe8P4XPyhoF6J2Py0MCzRxSKGeybh8= X-Google-Smtp-Source: AGHT+IFhk4Z0qNCqkvA/NeeJqLzSLEHXt1KUHpQBwVgkrfEt0ia0EChFth0//lAjz2j09JYbhrCBNA== X-Received: by 2002:a17:90a:9f0a:b0:269:38c2:dbd8 with SMTP id n10-20020a17090a9f0a00b0026938c2dbd8mr7855773pjp.25.1691462928673; Mon, 07 Aug 2023 19:48:48 -0700 (PDT) Received: from Thaum.localdomain (59-102-120-25.tpgi.com.au. [59.102.120.25]) by smtp.gmail.com with ESMTPSA id 9-20020a17090a190900b00256a4d59bfasm10159043pjg.23.2023.08.07.19.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 19:48:48 -0700 (PDT) Date: Tue, 8 Aug 2023 12:48:43 +1000 From: Nathaniel Shead 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-Type: text/plain; charset=us-ascii 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,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 List-Id: Sorry, noticed I provided the wrong version of the test. Here is the correct version (not relying on 'namespace std' being implicitly defined). Bootstrapped + regtested on x86_64-pc-linux-gnu. -- 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 d7ef5b34d42..119a14d03b9 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -16506,10 +16506,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 @@ -16530,13 +16526,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..1df8b162743 --- /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(N) 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" } -- 2.41.0