]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix error recovery ICE in tsubst_baselink [PR120876]
authorJakub Jelinek <jakub@redhat.com>
Thu, 20 Nov 2025 07:19:32 +0000 (08:19 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 20 Nov 2025 07:19:32 +0000 (08:19 +0100)
The following testcase ICEs since r12-6080.  The problem is that
lookup_fnfields can return NULL_TREE on failure, but the maybe_incomplete
handling was added before the if (!baselink) handling and assumes that
baselink is non-NULL (and BASELINK).

The following patch reorders the if (maybe_incomplete) handling with
if (!baselink).

2025-11-20  Jakub Jelinek  <jakub@redhat.com>

PR c++/120876
* pt.cc (tsubst_baselink): Move maybe_incomplete handling after
!baselink handling.

* g++.dg/parse/crash81.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/parse/crash81.C [new file with mode: 0644]

index 0daf43c681b141aa14c001a72e23c493a117a07f..27d786d0e7779ecba2075cb76a57e62593a5d64f 100644 (file)
@@ -17627,19 +17627,6 @@ tsubst_baselink (tree baselink, tree object_type,
       bool maybe_incomplete = BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink);
       baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1,
                                  complain);
-      if (maybe_incomplete)
-       {
-         /* Filter out from the new lookup set those functions which didn't
-            appear in the original lookup set (in a less specialized form).
-            This is needed to preserve the consistency of member lookup
-            performed in an incomplete-class context, within which
-            later-declared members ought to remain invisible.  */
-         BASELINK_FUNCTIONS (baselink)
-           = filter_memfn_lookup (fns, BASELINK_FUNCTIONS (baselink),
-                                  binfo_type);
-         BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true;
-       }
-
       if (!baselink)
        {
          if (complain & tf_error)
@@ -17657,6 +17644,19 @@ tsubst_baselink (tree baselink, tree object_type,
          return error_mark_node;
        }
 
+      if (maybe_incomplete)
+       {
+         /* Filter out from the new lookup set those functions which didn't
+            appear in the original lookup set (in a less specialized form).
+            This is needed to preserve the consistency of member lookup
+            performed in an incomplete-class context, within which
+            later-declared members ought to remain invisible.  */
+         BASELINK_FUNCTIONS (baselink)
+           = filter_memfn_lookup (fns, BASELINK_FUNCTIONS (baselink),
+                                  binfo_type);
+         BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true;
+       }
+
       fns = BASELINK_FUNCTIONS (baselink);
     }
   else
diff --git a/gcc/testsuite/g++.dg/parse/crash81.C b/gcc/testsuite/g++.dg/parse/crash81.C
new file mode 100644 (file)
index 0000000..6841162
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/120876
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct S {
+  static bool foo (decltype (bar (T {})));     // { dg-error "'bar' was not declared in this scope; did you mean 'baz'\\\?" }
+  static constexpr bool s = foo (0);           // { dg-error "declaration of 'S<int>::foo' depends on itself" }
+};
+
+void
+baz ()
+{
+  S <int>::s;
+}