Skip to content

Commit 0183b58

Browse files
authored
[Clang] Correctly diagnose a static function overloading a non-static function (#93460)
Regression in clang 18 introduced by af47517 Fixes #93456
1 parent 8def128 commit 0183b58

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ Bug Fixes to C++ Support
797797
in dependent contexts. Fixes (#GH92680).
798798
- Fixed a crash when diagnosing failed conversions involving template parameter
799799
packs. (#GH93076)
800+
- Fixed a regression introduced in Clang 18 causing a static function overloading a non-static function
801+
with the same parameters not to be diagnosed. (Fixes #GH93456).
800802

801803
Bug Fixes to AST Handling
802804
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
14821482
}
14831483

14841484
if (OldMethod && NewMethod && !OldMethod->isStatic() &&
1485-
!OldMethod->isStatic()) {
1485+
!NewMethod->isStatic()) {
14861486
bool HaveCorrespondingObjectParameters = [&](const CXXMethodDecl *Old,
14871487
const CXXMethodDecl *New) {
14881488
auto NewObjectType = New->getFunctionObjectParameterReferenceType();

clang/test/SemaCXX/overload-decl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ class X {
3636

3737
int main() {} // expected-note {{previous definition is here}}
3838
int main(int,char**) {} // expected-error {{conflicting types for 'main'}}
39+
40+
41+
namespace GH93456 {
42+
43+
struct X {
44+
static void f(); // expected-note {{previous declaration is here}}
45+
void f() const;
46+
// expected-error@-1 {{static and non-static member functions with the same parameter types cannot be overloaded}}
47+
};
48+
49+
struct Y {
50+
void f() const; // expected-note {{previous declaration is here}}
51+
static void f();
52+
// expected-error@-1 {{static and non-static member functions with the same parameter types cannot be overloaded}}
53+
};
54+
55+
}

0 commit comments

Comments
 (0)