Skip to content

Commit ebd9a24

Browse files
committed
[clang] Fix typos in member initializers
This was regressed in ca61961. As we attached InitExprs as-is to the AST, without performing transformations. Differential Revision: https://reviews.llvm.org/D142187
1 parent 269cfd3 commit ebd9a24

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,9 +4098,11 @@ void Sema::ActOnFinishCXXInClassMemberInitializer(Decl *D,
40984098
return;
40994099
}
41004100

4101-
ExprResult Init = InitExpr;
4102-
if (!FD->getType()->isDependentType() && !InitExpr->isTypeDependent()) {
4103-
Init = ConvertMemberDefaultInitExpression(FD, InitExpr, InitLoc);
4101+
ExprResult Init = CorrectDelayedTyposInExpr(InitExpr, /*InitDecl=*/nullptr,
4102+
/*RecoverUncorrectedTypos=*/true);
4103+
assert(Init.isUsable() && "Init should at least have a RecoveryExpr");
4104+
if (!FD->getType()->isDependentType() && !Init.get()->isTypeDependent()) {
4105+
Init = ConvertMemberDefaultInitExpression(FD, Init.get(), InitLoc);
41044106
// C++11 [class.base.init]p7:
41054107
// The initialization of each base and member constitutes a
41064108
// full-expression.
@@ -4112,9 +4114,7 @@ void Sema::ActOnFinishCXXInClassMemberInitializer(Decl *D,
41124114
}
41134115
}
41144116

4115-
InitExpr = Init.get();
4116-
4117-
FD->setInClassInitializer(InitExpr);
4117+
FD->setInClassInitializer(Init.get());
41184118
}
41194119

41204120
/// Find the direct and/or virtual base specifiers that

clang/test/PCH/typo3.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: not %clang_cc1 -emit-pch %s -o %t.pch 2>&1 | FileCheck %s
2+
3+
struct S {
4+
// Make sure TypoExprs in default init exprs are corrected before serializing
5+
// in PCH.
6+
int y = bar;
7+
// CHECK: use of undeclared identifier 'bar'
8+
};

0 commit comments

Comments
 (0)