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 BBEBB385782B for ; Tue, 8 Aug 2023 20:04:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBEBB385782B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691525051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2AY3kEPM68wZOWMQSKSo3OtBK26oC/k0/HlxMmTo+lM=; b=D2PYEOINuUuoX26wGBEuEMADbaQTsV2N30nfd5OS5LdC1vw6oD0HnvYUhKUbXKFNoRXqoO CRKf9caUwvm3ZsK1KOV5+6rtyJCR21c/6AE/jHBtHavS13GBQKlWhwCytMm/dAoZc+5feK 3dHoiEJY4gFuajxbfiux6p5BvUsNTMY= Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-m5eR96IhOp6c_hhQzDEqpQ-1; Tue, 08 Aug 2023 16:04:10 -0400 X-MC-Unique: m5eR96IhOp6c_hhQzDEqpQ-1 Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-56c68e1d44cso10372977eaf.2 for ; Tue, 08 Aug 2023 13:04:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691525049; x=1692129849; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2AY3kEPM68wZOWMQSKSo3OtBK26oC/k0/HlxMmTo+lM=; b=Oxl8eMO6TKog9vbeAWz1pdcKqocnJkHLvHkCb3rBe2Eev6UFh2J/SurWeRjA/jMLf8 cr470rznvTviw7R5NgiMdgaH5LGJJeLpLE5IHWCw7PxsFXkVaxDGBEvIKvp6x0bH8pYx 7h8RLfaEPApQTshM+vgjIC0uwrshG40D26kk6XYQ9feCD+qVTDt4g70kOjUkJBE2+XeD bIYnLlZV4Yvgcm7n3asyPzSg6DvTcDwesHvrtkJOz4qkSqoEjmKLz44bXHd+AdaZss4h /T/vq8kzgL+Asl1Rmo/9De+GwSAIRH+cgn/z6EllzWhDFCWA9rgHAo2POGBRjXMNBpgk E1Sw== X-Gm-Message-State: AOJu0YwoSJggXdqtsd7+8deGMf3xPK1CivFqLxBOfdUr6HEXgnK89ZSD zh7Zx6ujFBH323C9jrP32hGNi0snu+DTZl13vK4N9BjINIyOBYr02R13aLV2w6dCXwciExgjgb4 b6n7NxQHW4O2eqdAYGg== X-Received: by 2002:a05:6358:9214:b0:13a:1e90:4813 with SMTP id d20-20020a056358921400b0013a1e904813mr422539rwb.29.1691525049290; Tue, 08 Aug 2023 13:04:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFunpgrj8zkOw3A9wy0amgSBCl2M6v2ikxOvO7bn1YsxJAJyaNGPC24qVFVUjmG4tEPBEoJ2Q== X-Received: by 2002:a05:6358:9214:b0:13a:1e90:4813 with SMTP id d20-20020a056358921400b0013a1e904813mr422518rwb.29.1691525048945; Tue, 08 Aug 2023 13:04:08 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id x15-20020a0ce0cf000000b0063d193369c3sm3864330qvk.29.2023.08.08.13.04.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Aug 2023 13:04:08 -0700 (PDT) Message-ID: <15535b32-d359-985a-a74d-ca8dcc93f9a1@redhat.com> Date: Tue, 8 Aug 2023 16:04:07 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] c++: Report invalid id-expression in decltype [PR100482] To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Patrick Palka References: <4cd26c62-2ecf-db54-f180-9fe4be282449@idea> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: On 8/7/23 22:48, Nathaniel Shead wrote: > 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. Pushed, thanks! > -- 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" }