[PATCH] D115567: [Sema] Add FixIt when a C++ out-of-line method has extra/missing const
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 10 18:14:19 PST 2021
sammccall created this revision.
sammccall added a reviewer: hokein.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
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:"{{.*}}":{10:15-10:15}:" const"
+int Foo::get() {} // expected-error {{does not match any declaration}}
+// CHECK: fix-it:"{{.*}}":{12:20-12: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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115567.393646.patch
Type: text/x-patch
Size: 1778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211211/660b8f7e/attachment.bin>
More information about the cfe-commits
mailing list