https://github.com/dingcyrus updated https://github.com/llvm/llvm-project/pull/219905
>From 143c4e3c9a7ef29da5454e8c483de09cf789a4b3 Mon Sep 17 00:00:00 2001 From: Cyrus Ding <[email protected]> Date: Mon, 31 Aug 2026 15:39:16 +0800 Subject: [PATCH 1/2] [Clang] Fix wording of ref-qualifier overload diagnostic When a member function is redeclared with a conflicting ref-qualifier, the diagnostic described the new declaration before the previous declaration, which read in the opposite order from the source. For example, struct C { void f(); }; void C::f() & {} previously produced: cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier Swap the two qualifier descriptions so the previous declaration is described first, matching source order: cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&' Fixes #219803 --- clang/lib/Sema/SemaOverload.cpp | 2 +- clang/test/CXX/drs/cwg24xx.cpp | 6 +++--- clang/test/CXX/drs/cwg5xx.cpp | 4 ++-- clang/test/CXX/over/over.load/p2-0x.cpp | 6 +++--- clang/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 24b41a68db0fd..106ddb90ed9dc 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -1528,7 +1528,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New, if (!UseMemberUsingDeclRules && (OldMethod->getRefQualifier() == RQ_None || NewMethod->getRefQualifier() == RQ_None)) { SemaRef.Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload) - << NewMethod->getRefQualifier() << OldMethod->getRefQualifier(); + << OldMethod->getRefQualifier() << NewMethod->getRefQualifier(); SemaRef.Diag(OldMethod->getLocation(), diag::note_previous_declaration); return true; } diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp index 5d6ec58b4caef..c84eac1aa9543 100644 --- a/clang/test/CXX/drs/cwg24xx.cpp +++ b/clang/test/CXX/drs/cwg24xx.cpp @@ -209,13 +209,13 @@ struct S { struct T : S { virtual void f() &; - // expected-error@-1 {{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}} + // expected-error@-1 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} // expected-note@#cwg2496-f {{previous declaration is here}} virtual void g(); - // expected-error@-1 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} + // expected-error@-1 {{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}} // expected-note@#cwg2496-g {{previous declaration is here}} virtual void h() &&; - // expected-error@-1 {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}} + // expected-error@-1 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'}} // expected-note@#cwg2496-h {{previous declaration is here}} virtual void i(); virtual void j() &; diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp index 374ebf09baf34..16f3e963b4c93 100644 --- a/clang/test/CXX/drs/cwg5xx.cpp +++ b/clang/test/CXX/drs/cwg5xx.cpp @@ -959,12 +959,12 @@ namespace cwg574 { // cwg574: 3.0 #elif __cplusplus >= 201103L // FIXME: We shouldn't produce the 'cannot overload' diagnostics here. friend C &C::operator=(const C&); // #cwg574-test-C - // since-cxx11-error@#cwg574-test-C {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} + // since-cxx11-error@#cwg574-test-C {{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}} // since-cxx11-note@#cwg574-C-copy-assign {{previous declaration is here}} // since-cxx11-error@#cwg574-test-C {{friend declaration of 'operator=' does not match any declaration in 'cwg574::C'}} // since-cxx11-note@#cwg574-C-copy-assign {{candidate function}} friend D &D::operator=(const D&); // #cwg574-test-D - // since-cxx11-error@#cwg574-test-D {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'}} + // since-cxx11-error@#cwg574-test-D {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}} // since-cxx11-note@#cwg574-D-copy-assign {{previous declaration is here}} // since-cxx11-error@#cwg574-test-D {{friend declaration of 'operator=' does not match any declaration in 'cwg574::D'}} // since-cxx11-note@#cwg574-D-copy-assign {{candidate function}} diff --git a/clang/test/CXX/over/over.load/p2-0x.cpp b/clang/test/CXX/over/over.load/p2-0x.cpp index 94185963ff5c7..513d6874ea0ac 100644 --- a/clang/test/CXX/over/over.load/p2-0x.cpp +++ b/clang/test/CXX/over/over.load/p2-0x.cpp @@ -12,16 +12,16 @@ class Y { void h() const &; void h() &&; void i() &; // expected-note{{previous declaration}} - void i() const; // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} + void i() const; // expected-error{{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}} template<typename T> void f(T*) &; template<typename T> void f(T*) &&; template<typename T> void g(T*) &; // expected-note{{previous declaration}} - template<typename T> void g(T*); // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} + template<typename T> void g(T*); // expected-error{{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}} void k(); // expected-note{{previous declaration}} - void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}} + void k() &&; // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'}} }; struct GH76358 { diff --git a/clang/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp b/clang/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp index b066f9ab63410..39465e2dfdb3b 100644 --- a/clang/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp +++ b/clang/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp @@ -86,7 +86,7 @@ namespace extended_examples { } } -//expected-error@71 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'}} +//expected-error@71 {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}} //expected-note@70 {{previous declaration is here}} //expected-error@82 {{statement requires expression of integer type ('A2' invalid)}} //expected-error@83 {{statement requires expression of integer type ('A3' invalid)}} >From f058a7778b9767286937571fd105145f29a6d253 Mon Sep 17 00:00:00 2001 From: Cyrus Ding <[email protected]> Date: Mon, 31 Aug 2026 16:02:23 +0800 Subject: [PATCH 2/2] [Clang] Add release note for ref-qualifier overload diagnostic change Update the release notes to document the reworded `cannot overload a member function` diagnostic, which now describes the previous declaration first. --- clang/docs/ReleaseNotes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index bdbabf2cd98d0..7be901d62f8b0 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -243,6 +243,10 @@ features cannot lower the translation-unit ABI level; ### Improvements to Clang's diagnostics +- The `cannot overload a member function` diagnostic now describes the previous + declaration first, matching the order in which the declarations appear in the + source. (#GH219803) + - More consistent rendering of Unicode characters in diagnostic messages. - Fixed `-Wunused-parameter` to diagnose coroutine parameters that are only _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
