llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Serosh (Serosh-commits)

<details>
<summary>Changes</summary>

`CXXRecordDecl::forallBases()` can be called during template instantiation for 
a record that has no definition so in  that case calling `bases()` asserts 
because the record's `DefinitionData` is null , so fix this  by checking 
`hasDefinition()` before iterating over the record's bases. If the record has 
no definition, return `false`, matching the existing behavior for cases where 
the base classes cannot be computed

Fixes #<!-- -->195133

---
Full diff: https://github.com/llvm/llvm-project/pull/199403.diff


2 Files Affected:

- (modified) clang/lib/AST/CXXInheritance.cpp (+3) 
- (modified) clang/test/SemaTemplate/current-instantiation.cpp (+15) 


``````````diff
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 29f5916284ebb..23a9f112f9bcd 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -127,6 +127,9 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 
   const CXXRecordDecl *Record = this;
   while (true) {
+    if (!Record->hasDefinition())
+      return false;
+
     for (const auto &I : Record->bases()) {
       const auto *Base = I.getType()->getAsCXXRecordDecl();
       if (!Base || !(Base->isBeingDefined() || Base->isCompleteDefinition()))
diff --git a/clang/test/SemaTemplate/current-instantiation.cpp 
b/clang/test/SemaTemplate/current-instantiation.cpp
index 9214bbeb973d6..fdc98638b3923 100644
--- a/clang/test/SemaTemplate/current-instantiation.cpp
+++ b/clang/test/SemaTemplate/current-instantiation.cpp
@@ -247,3 +247,18 @@ namespace RebuildDependentScopeDeclRefExpr {
   // FIXME: We should issue a typo-correction here.
   template<typename T> N<X<T>::think> X<T>::foo() {} // expected-error {{no 
member named 'think' in 'RebuildDependentScopeDeclRefExpr::X<T>'}}
 }
+
+namespace GH195133 {
+  template <typename T> struct A {
+    void f();
+  };
+
+  template <typename T> struct X {
+    struct S : A<int> {};
+    static void f(S *p) {
+      p->template A<int>::f();
+    }
+  };
+
+  void g() { X<int>::f(nullptr); }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/199403
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to