[clang] [Clang] Correctly diagnose a static function overloading a non-static function (PR #93460)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 27 04:55:53 PDT 2024
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/93460
>From 3da162c93cbb75025e8283132fdcd20d740982a9 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 27 May 2024 13:30:50 +0200
Subject: [PATCH 1/2] [Clang] Correctly diagnose a static function overloading
a non-static function.
Regression in clang 18 introduced by af4751738db89a1
Fixes #93456
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Sema/SemaOverload.cpp | 2 +-
clang/test/SemaCXX/overload-decl.cpp | 17 +++++++++++++++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81b8d42aaa84e..bbd55f15a1dbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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 #93456).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 61d3c1633a2b7..c38164b7652f2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -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();
diff --git a/clang/test/SemaCXX/overload-decl.cpp b/clang/test/SemaCXX/overload-decl.cpp
index 1201396996e75..5d1df89a0da7b 100644
--- a/clang/test/SemaCXX/overload-decl.cpp
+++ b/clang/test/SemaCXX/overload-decl.cpp
@@ -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 at -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 at -1 {{static and non-static member functions with the same parameter types cannot be overloaded}}
+};
+
+}
>From 04c2cf99578994bd874bf9791ecb21f22405ef4a Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 27 May 2024 13:55:37 +0200
Subject: [PATCH 2/2] fix changelog
---
clang/docs/ReleaseNotes.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bbd55f15a1dbb..f5d0b69faf78d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -798,7 +798,7 @@ Bug Fixes to C++ Support
- 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 #93456).
+ with the same parameters not to be diagnosed. (Fixes #GH93456).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
More information about the cfe-commits
mailing list