[gcc r14-9264] c++/modules: complete_vars ICE with non-exported constexpr var
Patrick Palka
ppalka@gcc.gnu.org
Fri Mar 1 21:50:49 GMT 2024
https://gcc.gnu.org/g:e15ef78e4a1e50a51a92468e32186fbad59dd628
commit r14-9264-ge15ef78e4a1e50a51a92468e32186fbad59dd628
Author: Patrick Palka <ppalka@redhat.com>
Date: Fri Mar 1 16:50:20 2024 -0500
c++/modules: complete_vars ICE with non-exported constexpr var
Here after stream-in of the non-exported constexpr global 'A a' we call
maybe_register_incomplete_var, which we'd expect to be a no-op here but
it manages to take its second branch and pushes {a, NULL_TREE} onto
incomplete_vars. Later after defining B we ICE from complete_vars due
to this pushed NULL_TREE class context.
Judging by the two commits that introduced/modified this part of
maybe_register_incomplete_var, r196852 and r214333, it seems this second
branch is only concerned with constexpr static data members (whose
initializer may contain a pointer-to-member for a not-yet-complete class)
So this patch restricts this branch accordingly so it's not inadvertently
taken during stream-in.
gcc/cp/ChangeLog:
* decl.cc (maybe_register_incomplete_var): Restrict second
branch to static data members from a not-yet-complete class.
gcc/testsuite/ChangeLog:
* g++.dg/modules/cexpr-4_a.C: New test.
* g++.dg/modules/cexpr-4_b.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diff:
---
gcc/cp/decl.cc | 2 ++
gcc/testsuite/g++.dg/modules/cexpr-4_a.C | 10 ++++++++++
gcc/testsuite/g++.dg/modules/cexpr-4_b.C | 6 ++++++
3 files changed, 18 insertions(+)
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 993d7ef4d2b..dbc3df24e77 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -18979,6 +18979,8 @@ maybe_register_incomplete_var (tree var)
vec_safe_push (incomplete_vars, iv);
}
else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
+ && DECL_CLASS_SCOPE_P (var)
+ && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
&& decl_constant_var_p (var)
&& (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
{
diff --git a/gcc/testsuite/g++.dg/modules/cexpr-4_a.C b/gcc/testsuite/g++.dg/modules/cexpr-4_a.C
new file mode 100644
index 00000000000..44eea35a09f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/cexpr-4_a.C
@@ -0,0 +1,10 @@
+// { dg-additional-options "-fmodules-ts" }
+export module Cexpr4;
+// { dg-module-cmi "Cexpr4" }
+
+struct A { int m = 42; };
+
+constexpr A a;
+
+export
+inline int f() { return a.m; }
diff --git a/gcc/testsuite/g++.dg/modules/cexpr-4_b.C b/gcc/testsuite/g++.dg/modules/cexpr-4_b.C
new file mode 100644
index 00000000000..8ead58e4ddb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/cexpr-4_b.C
@@ -0,0 +1,6 @@
+// { dg-additional-options "-fmodules-ts" }
+import Cexpr4;
+
+int v = f();
+
+struct B { };
More information about the Gcc-cvs
mailing list