[PATCH] D142187: [clang] Fix typos in member initializers

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 20 06:20:45 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGebd9a2477e69: [clang] Fix typos in member initializers (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142187/new/

https://reviews.llvm.org/D142187

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/PCH/typo3.cpp


Index: clang/test/PCH/typo3.cpp
===================================================================
--- /dev/null
+++ clang/test/PCH/typo3.cpp
@@ -0,0 +1,8 @@
+// RUN: not %clang_cc1 -emit-pch %s -o %t.pch 2>&1 | FileCheck %s
+
+struct S {
+  // Make sure TypoExprs in default init exprs are corrected before serializing
+  // in PCH.
+  int y = bar;
+  // CHECK: use of undeclared identifier 'bar'
+};
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -4098,9 +4098,11 @@
     return;
   }
 
-  ExprResult Init = InitExpr;
-  if (!FD->getType()->isDependentType() && !InitExpr->isTypeDependent()) {
-    Init = ConvertMemberDefaultInitExpression(FD, InitExpr, InitLoc);
+  ExprResult Init = CorrectDelayedTyposInExpr(InitExpr, /*InitDecl=*/nullptr,
+                                              /*RecoverUncorrectedTypos=*/true);
+  assert(Init.isUsable() && "Init should at least have a RecoveryExpr");
+  if (!FD->getType()->isDependentType() && !Init.get()->isTypeDependent()) {
+    Init = ConvertMemberDefaultInitExpression(FD, Init.get(), InitLoc);
     // C++11 [class.base.init]p7:
     //   The initialization of each base and member constitutes a
     //   full-expression.
@@ -4112,9 +4114,7 @@
     }
   }
 
-  InitExpr = Init.get();
-
-  FD->setInClassInitializer(InitExpr);
+  FD->setInClassInitializer(Init.get());
 }
 
 /// Find the direct and/or virtual base specifiers that


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142187.490805.patch
Type: text/x-patch
Size: 1523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230120/6d9f4b29/attachment.bin>


More information about the cfe-commits mailing list