File tree 3 files changed +46
-0
lines changed
3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -1068,6 +1068,12 @@ class Sema {
1068
1068
// / same special member, we should act as if it is not yet declared.
1069
1069
llvm::SmallSet<SpecialMemberDecl, 4 > SpecialMembersBeingDeclared;
1070
1070
1071
+ // / The function definitions which were renamed as part of typo-correction
1072
+ // / to match their respective declarations. We want to keep track of them
1073
+ // / to ensure that we don't emit a "redefinition" error if we encounter a
1074
+ // / correctly named definition after the renamed definition.
1075
+ llvm::SmallPtrSet<const NamedDecl *, 4 > TypoCorrectedFunctionDefinitions;
1076
+
1071
1077
void ReadMethodPool (Selector Sel);
1072
1078
void updateOutOfDateSelector (Selector Sel);
1073
1079
@@ -3117,6 +3123,8 @@ class Sema {
3117
3123
const PartialDiagnostic &PrevNote,
3118
3124
bool ErrorRecovery = true );
3119
3125
3126
+ void MarkTypoCorrectedFunctionDefinition (const NamedDecl *F);
3127
+
3120
3128
void FindAssociatedClassesAndNamespaces (SourceLocation InstantiationLoc,
3121
3129
ArrayRef<Expr *> Args,
3122
3130
AssociatedNamespaceSet &AssociatedNamespaces,
Original file line number Diff line number Diff line change @@ -7424,6 +7424,10 @@ class DifferentNameValidatorCCC : public CorrectionCandidateCallback {
7424
7424
7425
7425
} // end anonymous namespace
7426
7426
7427
+ void Sema::MarkTypoCorrectedFunctionDefinition(const NamedDecl *F) {
7428
+ TypoCorrectedFunctionDefinitions.insert(F);
7429
+ }
7430
+
7427
7431
/// \brief Generate diagnostics for an invalid function redeclaration.
7428
7432
///
7429
7433
/// This routine handles generating the diagnostic messages for an invalid
@@ -7521,6 +7525,8 @@ static NamedDecl *DiagnoseInvalidRedeclaration(
7521
7525
if ((*I)->getCanonicalDecl() == Canonical)
7522
7526
Correction.setCorrectionDecl(*I);
7523
7527
7528
+ // Let Sema know about the correction.
7529
+ SemaRef.MarkTypoCorrectedFunctionDefinition(Result);
7524
7530
SemaRef.diagnoseTypo(
7525
7531
Correction,
7526
7532
SemaRef.PDiag(IsLocalFriend
@@ -11732,6 +11738,11 @@ Sema::CheckForFunctionRedefinition(FunctionDecl *FD,
11732
11738
if (canRedefineFunction(Definition, getLangOpts()))
11733
11739
return;
11734
11740
11741
+ // Don't emit an error when this is redifinition of a typo-corrected
11742
+ // definition.
11743
+ if (TypoCorrectedFunctionDefinitions.count(Definition))
11744
+ return;
11745
+
11735
11746
// If we don't have a visible definition of the function, and it's inline or
11736
11747
// a template, skip the new definition.
11737
11748
if (SkipBody && !hasVisibleDefinition(Definition) &&
Original file line number Diff line number Diff line change @@ -679,3 +679,30 @@ int g() {
679
679
sizeof (c0is0)]; // expected-error {{use of undeclared identifier}}
680
680
};
681
681
}
682
+
683
+ namespace avoidRedundantRedefinitionErrors {
684
+ class Class {
685
+ void function (int pid); // expected-note {{'function' declared here}}
686
+ };
687
+
688
+ void Class::function2 (int pid) { // expected-error {{out-of-line definition of 'function2' does not match any declaration in 'avoidRedundantRedefinitionErrors::Class'; did you mean 'function'?}}
689
+ }
690
+
691
+ // Expected no redefinition error here.
692
+ void Class::function (int pid) { // expected-note {{previous definition is here}}
693
+ }
694
+
695
+ void Class::function (int pid) { // expected-error {{redefinition of 'function'}}
696
+ }
697
+
698
+ namespace ns {
699
+ void create_test (); // expected-note {{'create_test' declared here}}
700
+ }
701
+
702
+ void ns::create_test2 () { // expected-error {{out-of-line definition of 'create_test2' does not match any declaration in namespace 'avoidRedundantRedefinitionErrors::ns'; did you mean 'create_test'?}}
703
+ }
704
+
705
+ // Expected no redefinition error here.
706
+ void ns::create_test () {
707
+ }
708
+ }
You can’t perform that action at this time.
0 commit comments