diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -8504,7 +8504,14 @@ << 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 diff --git a/clang/test/FixIt/member-mismatch.cpp b/clang/test/FixIt/member-mismatch.cpp new file mode 100644 --- /dev/null +++ b/clang/test/FixIt/member-mismatch.cpp @@ -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}}