[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 24 05:48:24 PST 2023
================
@@ -2252,6 +2252,176 @@ TEST_F(StructuralEquivalenceStmtTest, UnaryOperatorDifferentOps) {
EXPECT_FALSE(testStructuralMatch(t));
}
+TEST_F(StructuralEquivalenceStmtTest,
+ CXXOperatorCallExprVsUnaryBinaryOperator) {
+ auto t = makeNamedDecls(
+ R"(
+ template <typename T, T x>
+ class A;
+ template <typename T, T x, T y>
+ void foo(
+ A<T, x + y>,
+ A<T, x - y>,
+ A<T, -x>,
+ A<T, x * y>,
+ A<T, *x>,
+ A<T, x / y>,
+ A<T, x % y>,
+ A<T, x ^ y>,
+ A<T, x & y>,
+ A<T, &x>,
+ A<T, x | y>,
+ A<T, ~x>,
+ A<T, !x>,
+ A<T, x < y>,
+ A<T, (x > y)>,
+ A<T, x << y>,
+ A<T, (x >> y)>,
+ A<T, x == y>,
+ A<T, x != y>,
+ A<T, x <= y>,
+ A<T, x >= y>,
+ A<T, x <=> y>,
+ A<T, x && y>,
+ A<T, x || y>,
+ A<T, ++x>,
+ A<T, --x>,
+ A<T, (x , y)>,
+ A<T, x ->* y>,
+ A<T, x -> y>
+ );
+ )",
+ R"(
+ struct Bar {
+ Bar& operator=(Bar&);
+ Bar& operator->();
+ };
+
+ Bar& operator+(Bar&, Bar&);
+ Bar& operator+(Bar&);
+ Bar& operator-(Bar&, Bar&);
+ Bar& operator-(Bar&);
+ Bar& operator*(Bar&, Bar&);
+ Bar& operator*(Bar&);
+ Bar& operator/(Bar&, Bar&);
+ Bar& operator%(Bar&, Bar&);
+ Bar& operator^(Bar&, Bar&);
+ Bar& operator&(Bar&, Bar&);
+ Bar& operator&(Bar&);
+ Bar& operator|(Bar&, Bar&);
+ Bar& operator~(Bar&);
+ Bar& operator!(Bar&);
+ Bar& operator<(Bar&, Bar&);
+ Bar& operator>(Bar&, Bar&);
+ Bar& operator+=(Bar&, Bar&);
+ Bar& operator-=(Bar&, Bar&);
+ Bar& operator*=(Bar&, Bar&);
+ Bar& operator/=(Bar&, Bar&);
+ Bar& operator%=(Bar&, Bar&);
+ Bar& operator^=(Bar&, Bar&);
+ Bar& operator&=(Bar&, Bar&);
+ Bar& operator|=(Bar&, Bar&);
+ Bar& operator<<(Bar&, Bar&);
+ Bar& operator>>(Bar&, Bar&);
+ Bar& operator<<=(Bar&, Bar&);
+ Bar& operator>>=(Bar&, Bar&);
+ Bar& operator==(Bar&, Bar&);
+ Bar& operator!=(Bar&, Bar&);
+ Bar& operator<=(Bar&, Bar&);
+ Bar& operator>=(Bar&, Bar&);
+ Bar& operator<=>(Bar&, Bar&);
+ Bar& operator&&(Bar&, Bar&);
+ Bar& operator||(Bar&, Bar&);
+ Bar& operator++(Bar&);
+ Bar& operator--(Bar&);
+ Bar& operator,(Bar&, Bar&);
+ Bar& operator->*(Bar&, Bar&);
+
+ template <typename T, T x>
+ class A;
+ template <typename T, T x, T y>
+ void foo(
+ A<T, x + y>,
+ A<T, x - y>,
+ A<T, -x>,
+ A<T, x * y>,
+ A<T, *x>,
+ A<T, x / y>,
+ A<T, x % y>,
+ A<T, x ^ y>,
+ A<T, x & y>,
+ A<T, &x>,
+ A<T, x | y>,
+ A<T, ~x>,
+ A<T, !x>,
+ A<T, x < y>,
+ A<T, (x > y)>,
+ A<T, x << y>,
+ A<T, (x >> y)>,
+ A<T, x == y>,
+ A<T, x != y>,
+ A<T, x <= y>,
+ A<T, x >= y>,
+ A<T, x <=> y>,
+ A<T, x && y>,
+ A<T, x || y>,
+ A<T, ++x>,
+ A<T, --x>,
+ A<T, (x , y)>,
+ A<T, x ->* y>,
+ A<T, x -> y>
+ );
+ )",
+ Lang_CXX20);
+ EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+ CXXOperatorCallExprVsUnaryBinaryOperatorNe) {
+ auto t = makeNamedDecls(
+ R"(
+ template <typename T, T x>
+ class A;
+ template <typename T, T x, T y>
+ void foo(
+ A<T, x + y>
+ );
+ )",
+ R"(
+ struct Bar;
+
+ Bar& operator+(Bar&, Bar&);
----------------
balazske wrote:
I do not know exactly what was the purpose, but likely it should be `operator -` instead.
https://github.com/llvm/llvm-project/pull/72242
More information about the cfe-commits
mailing list