public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: global-namespace-qualified var after class def [PR90107]
@ 2022-04-27 22:45 Marek Polacek
  2022-04-28  0:51 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2022-04-27 22:45 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-28  0:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 22:45 [PATCH] c++: global-namespace-qualified var after class def [PR90107] Marek Polacek
2022-04-28  0:51 ` Jason Merrill

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).