[clang] [Clang] Fix wording of ref-qualifier overload diagnostic (PR #219905)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 31 00:41:44 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Cyrus Ding (dingcyrus)

<details>
<summary>Changes</summary>

  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

---
Full diff: https://github.com/llvm/llvm-project/pull/219905.diff


5 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/test/CXX/drs/cwg24xx.cpp (+3-3) 
- (modified) clang/test/CXX/drs/cwg5xx.cpp (+2-2) 
- (modified) clang/test/CXX/over/over.load/p2-0x.cpp (+3-3) 
- (modified) clang/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp (+1-1) 


``````````diff
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 at -1 {{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}}
+    // expected-error at -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 at -1 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}}
+    // expected-error at -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 at -1 {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
+    // expected-error at -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 at 71 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'}}
+//expected-error at 71 {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
 //expected-note at 70 {{previous declaration is here}}
 //expected-error at 82 {{statement requires expression of integer type ('A2' invalid)}}
 //expected-error at 83 {{statement requires expression of integer type ('A3' invalid)}}

``````````

</details>


https://github.com/llvm/llvm-project/pull/219905


More information about the cfe-commits mailing list