[clang] [clang][Sema] Fix assertion crash on invalid concept template parameter (#225792) (PR #235408)

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 25 23:28:49 PDT 2026


================
@@ -1540,7 +1538,36 @@ namespace {
         Designator.setInvalid();
         return;
       }
+
+      if(Base){
+        // Mark invalid and return early if Base points to an invalid decl
+        if(const auto *VD = Base.dyn_cast<const ValueDecl *>()){
+          if(VD->isInvalidDecl()){
+            Designator.setInvalid();
+            return;
+          }
+        }
+        // Mark invalid and return early if Base points to an invalid type
+        QualType BaseTy = getType(Base).getNonReferenceType();
+        if(BaseTy.isNull() || BaseTy->containsErrors() || (!BaseTy->isPointerType() && !BaseTy->isArrayType())){
+          Designator.setInvalid();
+          return;
+        }
+      }
+
       if (checkSubobject(Info, E, CSK_ArrayToPointer)) {
+        /*
+        When a user writes invalid C++ code (e.g., declaring a 
+        variable as void and then illegally re-declaring/indexing 
+        it as an array), the AST node representing Base ends up
+        with an invalid or unexpected type structure. 
+        => getType(Base) does not fulfill either conditions, causing
+        the assert statement to fail and crash the compiler.
+        */
+       /*
+       To get a clean error, add a check before entering the above
+       if clause
+       */
----------------
Sriraj2911 wrote:

Good to know, thanks. I'll make sure to use // for comments in the future.

Also, as mentioned above, these files were accidentally included from a different issue and have been removed from this PR.

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


More information about the cfe-commits mailing list