[clang] ebd9a24 - [clang] Fix typos in member initializers

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


Author: Kadir Cetinkaya
Date: 2023-01-20T15:20:31+01:00
New Revision: ebd9a2477e69ed35b83256ae93cc7e069f5a37c4

URL: https://github.com/llvm/llvm-project/commit/ebd9a2477e69ed35b83256ae93cc7e069f5a37c4
DIFF: https://github.com/llvm/llvm-project/commit/ebd9a2477e69ed35b83256ae93cc7e069f5a37c4.diff

LOG: [clang] Fix typos in member initializers

This was regressed in ca619613801233ef2def8c3cc7d311d5ed0033cb. As we
attached InitExprs as-is to the AST, without performing transformations.

Differential Revision: https://reviews.llvm.org/D142187

Added: 
    clang/test/PCH/typo3.cpp

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 80cc6b0c01f37..749025c1258ff 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -4098,9 +4098,11 @@ void Sema::ActOnFinishCXXInClassMemberInitializer(Decl *D,
     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 @@ void Sema::ActOnFinishCXXInClassMemberInitializer(Decl *D,
     }
   }
 
-  InitExpr = Init.get();
-
-  FD->setInClassInitializer(InitExpr);
+  FD->setInClassInitializer(Init.get());
 }
 
 /// Find the direct and/or virtual base specifiers that

diff  --git a/clang/test/PCH/typo3.cpp b/clang/test/PCH/typo3.cpp
new file mode 100644
index 0000000000000..c286039400469
--- /dev/null
+++ b/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'
+};


        


More information about the cfe-commits mailing list