This revision was automatically updated to reflect the committed changes. sammccall marked an inline comment as done. Closed by commit rGe7007b69d43b: [Sema] Add FixIt when a C++ out-of-line method has extra/missing const (authored by sammccall).
Changed prior to commit: https://reviews.llvm.org/D115567?vs=393646&id=394536#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D115567/new/ https://reviews.llvm.org/D115567 Files: clang/lib/Sema/SemaDecl.cpp clang/test/FixIt/member-mismatch.cpp Index: clang/test/FixIt/member-mismatch.cpp =================================================================== --- /dev/null +++ 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}} Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ 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
Index: clang/test/FixIt/member-mismatch.cpp =================================================================== --- /dev/null +++ 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}} Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits