Skip to content

[Clang] Correctly diagnose a static function overloading a non-static function #93460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ Bug Fixes to C++ Support
in dependent contexts. Fixes (#GH92680).
- Fixed a crash when diagnosing failed conversions involving template parameter
packs. (#GH93076)
- Fixed a regression introduced in Clang 18 causing a static function overloading a non-static function
with the same parameters not to be diagnosed. (Fixes #GH93456).

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
}

if (OldMethod && NewMethod && !OldMethod->isStatic() &&
!OldMethod->isStatic()) {
!NewMethod->isStatic()) {
bool HaveCorrespondingObjectParameters = [&](const CXXMethodDecl *Old,
const CXXMethodDecl *New) {
auto NewObjectType = New->getFunctionObjectParameterReferenceType();
Expand Down
17 changes: 17 additions & 0 deletions clang/test/SemaCXX/overload-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ class X {

int main() {} // expected-note {{previous definition is here}}
int main(int,char**) {} // expected-error {{conflicting types for 'main'}}


namespace GH93456 {

struct X {
static void f(); // expected-note {{previous declaration is here}}
void f() const;
// expected-error@-1 {{static and non-static member functions with the same parameter types cannot be overloaded}}
};

struct Y {
void f() const; // expected-note {{previous declaration is here}}
static void f();
// expected-error@-1 {{static and non-static member functions with the same parameter types cannot be overloaded}}
};

}
Loading