[clang] [C++23] Fix infinite recursion (Clang 19.x regression) (PR #104829)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 19 11:32:24 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

<details>
<summary>Changes</summary>

d469794d0cdfd2fea50a6ce0c0e33abb242d744c was fixing an issue with triggering vtable instantiations, but it accidentally introduced infinite recursion when the type to be checked is the same as the type used in a base specifier or field declaration.

Fixes #<!-- -->104802

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-2) 
- (modified) clang/test/SemaCXX/gh102293.cpp (+12-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e05595e565d54a..c1fc61c263791a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7057,10 +7057,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
           return false;
 
         for (const CXXBaseSpecifier &B : RD->bases())
-          if (!Check(B.getType(), Check))
+          if (B.getType() != T && !Check(B.getType(), Check))
             return false;
         for (const FieldDecl *FD : RD->fields())
-          if (!Check(FD->getType(), Check))
+          if (FD->getType() != T && !Check(FD->getType(), Check))
             return false;
         return true;
       };
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
index 30629fc03bf6a9..ece9dfd21da11c 100644
--- a/clang/test/SemaCXX/gh102293.cpp
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 template <typename T> static void destroy() {
     T t;
@@ -20,3 +19,15 @@ struct S : HasVT {
   HasD<> v;
 };
 
+// Ensure we don't get infinite recursion from the check, however. See GH104802
+namespace GH104802 {
+class foo {       // expected-note {{definition of 'GH104802::foo' is not complete until the closing '}'}}
+  foo a;          // expected-error {{field has incomplete type 'foo'}}
+  virtual int c();
+};
+
+class bar : bar { // expected-error {{base class has incomplete type}} \
+                     expected-note {{definition of 'GH104802::bar' is not complete until the closing '}'}}
+  virtual int c();
+};
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/104829


More information about the cfe-commits mailing list