[clang] [clang] Handle templated operators with reversed arguments (PR #69595)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 01:59:44 PDT 2023
================
@@ -37,6 +37,25 @@ These changes are ones which we think may surprise users when upgrading to
Clang |release| because of the opportunity they pose for disruption to existing
code bases.
+- Fix a bug in reversed argument for templated operators.
+ This breaks code in C++20 which was previously accepted in C++17. Eg:
+
+ .. code-block:: cpp
+
+ struct P {};
+ template<class S> bool operator==(const P&, const S&);
+
+ struct A : public P {};
+ struct B : public P {};
+
+ bool ambiguous(A a, B b) { return a == b; } // This equality is now ambiguous in C++20.
+
+ template<class S> bool operator!=(const P&, const S&);
+ bool fine(A a, B b) { return a == b; } // Ok. Found a matching operator!=.
+
+ To reduce widespread breakages, as an extension, clang would accept this with a
+ ``-Wambiguous-reversed-operator`` warning.
----------------
ilya-biryukov wrote:
NIT: it reads as if it is a new warning, I suggest saying "Clang accepts this code with an existing warning -W...."
https://github.com/llvm/llvm-project/pull/69595
More information about the cfe-commits
mailing list