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.133.124]) by sourceware.org (Postfix) with ESMTPS id C02113858C36 for ; Fri, 23 Jun 2023 16:15:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C02113858C36 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=1687536936; 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: in-reply-to:in-reply-to:references:references; bh=XSsImrH0RMasVbI2ChEXvfKbt75etJ9AYxq1CrzFJ1c=; b=LDxr9jpmYJUmeskta1O+/6cc/bK0AKCKdxkWDSbttw7A8g6p9G+UfBO5AgBg3Dplzcckps eV+5PL2aOwAbOr9G87zEUfy/EcZ2UImlzipUZhY/w9zAvsQCb0oehEKaL/bL8GEiA7zGLT gJjMM8GgZ2X0ZMHxOXf6vgPONRrdE7k= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-tD_vgmSZNbS9gk0y2-sI0g-1; Fri, 23 Jun 2023 12:15:35 -0400 X-MC-Unique: tD_vgmSZNbS9gk0y2-sI0g-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-62fe5a90439so10360516d6.1 for ; Fri, 23 Jun 2023 09:15:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687536934; x=1690128934; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XSsImrH0RMasVbI2ChEXvfKbt75etJ9AYxq1CrzFJ1c=; b=kdGxKEJQ1C59q6mUdlxPoAQmGvY+t3qigti+juiw1Py1QS0/9zF+PBANX73o1YSwo8 23JgFQ++vDyPewf88gfGwDYqYXTxpSJUDHxNuauxpemZt58Er0E1ih1xqw1WorhyDN92 IovIDeZzoUePPASHYZmu1Yyw54zv/n9MuFjcqhdFJKog6TMSoeIlc5ANqJWIKnLphYgI ithnxxnQ0u+LV0OIGyedIl168oPSKYCPY0VA8u9i9mZRF/7mWYzDDn8AX1qIqMq1wfRD ujETzlY2TXbaF9GabbIWE/xCZ+oizyxXhxxW1Q7YiGe18I3ok7qeed4aUibV4lfNcM7s 6m0w== X-Gm-Message-State: AC+VfDwBmGNOHob+acVxRxSYOI5gcTHi09L5LIWTc+LkNJaiFtZiQFDp TZK0tBn7H1vhmF7lg+PQs28vgbMdi7p0mi8ZIzAm7kiwfbF+Q96ob8YsNhbmQ2BoUj1FBSJXTwb 5Q2G6vVMYd68dM6sVR9PGdh3hBg== X-Received: by 2002:a05:6214:d0b:b0:62d:f8e7:304a with SMTP id 11-20020a0562140d0b00b0062df8e7304amr23597141qvh.54.1687536933953; Fri, 23 Jun 2023 09:15:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JGkhdwTmF2zNmIstj8ju3gf2yJElP9DDXEf7afDewN0PYDaRKdC6jNMGEpx1XPZc3srhElw== X-Received: by 2002:a05:6214:d0b:b0:62d:f8e7:304a with SMTP id 11-20020a0562140d0b00b0062df8e7304amr23597125qvh.54.1687536933669; Fri, 23 Jun 2023 09:15:33 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id d9-20020a0cf0c9000000b00631fa7aa9f7sm4817319qvl.32.2023.06.23.09.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:15:33 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 23 Jun 2023 12:15:32 -0400 (EDT) To: Nathaniel Shead cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: Report invalid id-expression in decltype [PR100482] In-Reply-To: Message-ID: <4cd26c62-2ecf-db54-f180-9fe4be282449@idea> References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Sun, 30 Apr 2023, Nathaniel Shead via Gcc-patches wrote: > 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. LGTM. Some minor comments about the new testcase below: > > 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 We generally prefer to organize tests according to the language dialect they apply to and the langugae construct that they're primarily testing. In this case we could name the test e.g. gcc/testsuite/g++.dg/cpp0x/decltype-100482.C > @@ -0,0 +1,11 @@ > +// { dg-do compile { target c++10 } } We also usually mention the PR number in the test as a comment: // PR c++/100482 One benefit of doing so is that the git alias 'git gcc-commit-mklog' (https://gcc.gnu.org/gitwrite.html#vendor) will then automatically include the PR number in the commit message template. > + > +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" } > -- > 2.40.0 > >