[clang] [Clang][Interp] Fix the location of uninitialized base warning (PR #100761)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 30 09:42:58 PDT 2024


================
@@ -122,19 +124,21 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
   }
 
   // Check Fields in all bases
-  for (const Record::Base &B : R->bases()) {
+  for (auto [I, B] : llvm::enumerate(R->bases())) {
     Pointer P = BasePtr.atField(B.Offset);
     if (!P.isInitialized()) {
       const Descriptor *Desc = BasePtr.getDeclDesc();
-      if (Desc->asDecl())
-        S.FFDiag(BasePtr.getDeclDesc()->asDecl()->getLocation(),
-                 diag::note_constexpr_uninitialized_base)
+      if (const auto *CD = dyn_cast_or_null<CXXRecordDecl>(R->getDecl())) {
+        const auto &BS = *std::next(CD->bases_begin(), I);
+        S.FFDiag(BS.getBaseTypeLoc(), diag::note_constexpr_uninitialized_base)
+            << B.Desc->getType() << BS.getSourceRange();
+      } else {
+        SourceLocation Loc =
+            Desc->asDecl() ? BasePtr.getDeclDesc()->asDecl()->getLocation()
+                           : BasePtr.getDeclDesc()->asExpr()->getExprLoc();
+        S.FFDiag(Loc, diag::note_constexpr_uninitialized_base)
----------------
yronglin wrote:

Done.

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


More information about the cfe-commits mailing list