Issue #24580: Symbolic group references to open group in re patterns now are
explicitly forbidden as well as numeric group references.
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index c0f539d..67f84e9 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -675,6 +675,9 @@
                         if gid is None:
                             msg = "unknown group name %r" % name
                             raise source.error(msg, len(name) + 1)
+                        if not state.checkgroup(gid):
+                            raise source.error("cannot refer to an open group",
+                                               len(name) + 1)
                         state.checklookbehindgroup(gid, source)
                         subpatternappend((GROUPREF, gid))
                         continue