================
@@ -9267,14 +9267,14 @@ bool Sema::RequireLiteralType(SourceLocation Loc, 
QualType T,
   if (!RT)
     return true;
 
-  const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
-
   // A partially-defined class type can't be a literal type, because a literal
   // class type must have a trivial destructor (which can't be checked until
   // the class definition is complete).
   if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T))
     return true;
 
+  const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
----------------
a-tarasyuk wrote:

> I am also curious why this does not show up in C++, we obtain a similar 
> diagnostic but no crash.

Please correct me if I'm wrong, the `CXXRecordDecl` is specific to C++ 
declarations, so the cast works as expected. In a C env, `RecordDecl` is used 
instead. We could wrap this in a condition to check specifically for C++, but 
`*RD` isn't required for `RequireCompleteType`. `RequireCompleteType` handles 
cases related to incomplete C types, so I'm not sure if we need to perform 
additional checks here.

```cpp
if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T))
    return true;
```



https://github.com/llvm/llvm-project/pull/101426
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to