Skip to content

Commit f7e9d48

Browse files
authored
[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.
1 parent 4cdc19b commit f7e9d48

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Improvements to Clang's diagnostics
132132
template <typename> int i; // error: non-static data member 'i' cannot be declared as a template
133133
};
134134

135+
- Clang now has improved diagnostics for functions with explicit 'this' parameters. Fixes #GH97878
136+
135137
- Clang now diagnoses dangling references to fields of temporary objects. Fixes #GH81589.
136138

137139
- Clang now diagnoses undefined behavior in constant expressions more consistently. This includes invalid shifts, and signed overflow in arithmetic.

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11133,7 +11133,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
1113311133
if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn)) {
1113411134
if (I == 0)
1113511135
isObjectArgument = true;
11136-
else
11136+
else if (!Fn->hasCXXExplicitFunctionObjectParameter())
1113711137
I--;
1113811138
}
1113911139

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,3 +965,10 @@ void f();
965965
};
966966
void a::f(this auto) {} // expected-error {{an explicit object parameter cannot appear in a non-member function}}
967967
}
968+
969+
struct R {
970+
void f(this auto &&self, int &&r_value_ref) {} // expected-note {{candidate function template not viable: expects an rvalue for 2nd argument}}
971+
void g(int &&r_value_ref) {
972+
f(r_value_ref); // expected-error {{no matching member function for call to 'f'}}
973+
}
974+
};

0 commit comments

Comments
 (0)