[clang] f7e9d48 - [Clang] Fix confusing diagnositcs related to explicit this parameters (#100351)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 06:40:39 PDT 2024
Author: Braden Helmer
Date: 2024-07-29T09:40:35-04:00
New Revision: f7e9d48a73dd68c8b652692d8a9e559a6ceb722e
URL: https://github.com/llvm/llvm-project/commit/f7e9d48a73dd68c8b652692d8a9e559a6ceb722e
DIFF: https://github.com/llvm/llvm-project/commit/f7e9d48a73dd68c8b652692d8a9e559a6ceb722e.diff
LOG: [Clang] Fix confusing diagnositcs related to explicit this parameters (#100351)
Fixes #97878.
This PR improves diagnostics related to explicit 'this' parameters.
Previously, the 'this' parameter would be incorrectly underlined when
diagnosing a bad conversion.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ddad083571eb1..e93582b50cfb2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -132,6 +132,8 @@ Improvements to Clang's diagnostics
template <typename> int i; // error: non-static data member 'i' cannot be declared as a template
};
+- Clang now has improved diagnostics for functions with explicit 'this' parameters. Fixes #GH97878
+
- Clang now diagnoses dangling references to fields of temporary objects. Fixes #GH81589.
- Clang now diagnoses undefined behavior in constant expressions more consistently. This includes invalid shifts, and signed overflow in arithmetic.
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 86074a4f3a585..c5f56ac62b458 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11133,7 +11133,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn)) {
if (I == 0)
isObjectArgument = true;
- else
+ else if (!Fn->hasCXXExplicitFunctionObjectParameter())
I--;
}
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 4811b6052254c..45fee6514c12b 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -965,3 +965,10 @@ void f();
};
void a::f(this auto) {} // expected-error {{an explicit object parameter cannot appear in a non-member function}}
}
+
+struct R {
+ void f(this auto &&self, int &&r_value_ref) {} // expected-note {{candidate function template not viable: expects an rvalue for 2nd argument}}
+ void g(int &&r_value_ref) {
+ f(r_value_ref); // expected-error {{no matching member function for call to 'f'}}
+ }
+};
More information about the cfe-commits
mailing list