[Sema] Add FixIt when a C++ out-of-line method has extra/missing const

Differential Revision: https://reviews.llvm.org/D115567
This commit is contained in:
Sam McCall 2021-12-11 03:14:05 +01:00
parent 54fc9eb9b3
commit e7007b69d4
2 changed files with 20 additions and 1 deletions

View File

@ -8504,7 +8504,14 @@ static NamedDecl *DiagnoseInvalidRedeclaration(
<< NewFD->getParamDecl(Idx - 1)->getType();
} else if (FDisConst != NewFDisConst) {
SemaRef.Diag(FD->getLocation(), diag::note_member_def_close_const_match)
<< NewFDisConst << FD->getSourceRange().getEnd();
<< NewFDisConst << FD->getSourceRange().getEnd()
<< (NewFDisConst
? FixItHint::CreateRemoval(ExtraArgs.D.getFunctionTypeInfo()
.getConstQualifierLoc())
: FixItHint::CreateInsertion(ExtraArgs.D.getFunctionTypeInfo()
.getRParenLoc()
.getLocWithOffset(1),
" const"));
} else
SemaRef.Diag(FD->getLocation(),
IsMember ? diag::note_member_def_close_match

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -verify %s
// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
class Foo {
int get() const; // expected-note {{because it is const qualified}}
void set(int); // expected-note {{because it is not const qualified}}
};
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:15-[[@LINE+1]]:15}:" const"
int Foo::get() {} // expected-error {{does not match any declaration}}
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:20-[[@LINE+1]]:26}:""
void Foo::set(int) const {} // expected-error {{does not match any declaration}}