public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] c++: global-namespace-qualified var after class def [PR90107]
Date: Wed, 27 Apr 2022 18:45:26 -0400	[thread overview]
Message-ID: <20220427224526.1107353-1-polacek@redhat.com> (raw)

Here we wrongly reject the definition of "::N::a"

  struct A;
  namespace N { extern A a; }
  struct A {} ::N::a;

because our code to diagnose a missing ; after a class definition doesn't
realize that :: can follow a class definition.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11.4?

	PR c++/90107

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_class_specifier_1): Accept :: after a class
	definition.

gcc/testsuite/ChangeLog:

	* g++.dg/parse/qualified6.C: New test.
---
 gcc/cp/parser.cc                        |  1 +
 gcc/testsuite/g++.dg/parse/qualified6.C | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/parse/qualified6.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 169e6a62f5f..2235da10c7c 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -25933,6 +25933,7 @@ cp_parser_class_specifier_1 (cp_parser* parser)
       case CPP_OPEN_PAREN:
       case CPP_CLOSE_PAREN:
       case CPP_COMMA:
+      case CPP_SCOPE:
         want_semicolon = false;
         break;
 
diff --git a/gcc/testsuite/g++.dg/parse/qualified6.C b/gcc/testsuite/g++.dg/parse/qualified6.C
new file mode 100644
index 00000000000..68b51f771ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/qualified6.C
@@ -0,0 +1,10 @@
+// PR c++/90107
+// { dg-do compile }
+
+struct A;
+namespace N { extern A a; }
+struct A {} ::N::a;
+
+struct A1;
+struct B { static A1 a1; };
+struct A1 {} ::B::a1;

base-commit: 58e4a744b6e8140499ed6c33a8e9a6557e102f74
-- 
2.35.1


             reply	other threads:[~2022-04-27 22:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27 22:45 Marek Polacek [this message]
2022-04-28  0:51 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220427224526.1107353-1-polacek@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).