@@ -881,6 +881,137 @@ TEST(ExprMutationAnalyzerTest, CastToConstRef) {
881
881
EXPECT_FALSE (isMutated (Results, AST.get ()));
882
882
}
883
883
884
+ TEST (ExprMutationAnalyzerTest, CommaExprWithAnAssigment) {
885
+ const auto AST =
886
+ buildASTFromCodeWithArgs (" void f() { int x; int y; (x, y) = 5; }" ,
887
+ {" -Wno-unused-value" });
888
+ const auto Results =
889
+ match (withEnclosingCompound (declRefTo (" y" )), AST->getASTContext ());
890
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
891
+ }
892
+
893
+ TEST (ExprMutationAnalyzerTest, CommaExprWithDecOp) {
894
+ const auto AST =
895
+ buildASTFromCodeWithArgs (" void f() { int x; int y; (x, y)++; }" ,
896
+ {" -Wno-unused-value" });
897
+ const auto Results =
898
+ match (withEnclosingCompound (declRefTo (" y" )), AST->getASTContext ());
899
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
900
+ }
901
+
902
+ TEST (ExprMutationAnalyzerTest, CommaExprWithNonConstMemberCall) {
903
+ const auto AST =
904
+ buildASTFromCodeWithArgs (" class A { public: int mem; void f() { mem ++; } };"
905
+ " void fn() { A o1, o2; (o1, o2).f(); }" ,
906
+ {" -Wno-unused-value" });
907
+ const auto Results =
908
+ match (withEnclosingCompound (declRefTo (" o2" )), AST->getASTContext ());
909
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
910
+ }
911
+
912
+ TEST (ExprMutationAnalyzerTest, CommaExprWithConstMemberCall) {
913
+ const auto AST =
914
+ buildASTFromCodeWithArgs (" class A { public: int mem; void f() const { } };"
915
+ " void fn() { A o1, o2; (o1, o2).f(); }" ,
916
+ {" -Wno-unused-value" });
917
+ const auto Results =
918
+ match (withEnclosingCompound (declRefTo (" o2" )), AST->getASTContext ());
919
+ EXPECT_FALSE (isMutated (Results, AST.get ()));
920
+ }
921
+
922
+ TEST (ExprMutationAnalyzerTest, CommaExprWithCallExpr) {
923
+ const auto AST =
924
+ buildASTFromCodeWithArgs (" class A { public: int mem; void f(A &O1) {} };"
925
+ " void fn() { A o1, o2; o2.f((o2, o1)); }" ,
926
+ {" -Wno-unused-value" });
927
+ const auto Results =
928
+ match (withEnclosingCompound (declRefTo (" o1" )), AST->getASTContext ());
929
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
930
+ }
931
+
932
+ TEST (ExprMutationAnalyzerTest, CommaExprWithCallUnresolved) {
933
+ auto AST = buildASTFromCodeWithArgs (
934
+ " template <class T> struct S;"
935
+ " template <class T> void f() { S<T> s; int x, y; s.mf((y, x)); }" ,
936
+ {" -fno-delayed-template-parsing -Wno-unused-value" });
937
+ auto Results =
938
+ match (withEnclosingCompound (declRefTo (" x" )), AST->getASTContext ());
939
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
940
+
941
+ AST = buildASTFromCodeWithArgs (
942
+ " template <class T> void f(T t) { int x, y; g(t, (y, x)); }" ,
943
+ {" -fno-delayed-template-parsing -Wno-unused-value" });
944
+ Results = match (withEnclosingCompound (declRefTo (" x" )), AST->getASTContext ());
945
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
946
+ }
947
+
948
+ TEST (ExprMutationAnalyzerTest, CommaExprParmRef) {
949
+ const auto AST =
950
+ buildASTFromCodeWithArgs (" class A { public: int mem;};"
951
+ " extern void fn(A &o1);"
952
+ " void fn2 () { A o1, o2; fn((o2, o1)); } " ,
953
+ {" -Wno-unused-value" });
954
+ const auto Results =
955
+ match (withEnclosingCompound (declRefTo (" o1" )), AST->getASTContext ());
956
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
957
+ }
958
+
959
+ TEST (ExprMutationAnalyzerTest, CommaExprWithAmpersandOp) {
960
+ const auto AST =
961
+ buildASTFromCodeWithArgs (" class A { public: int mem;};"
962
+ " void fn () { A o1, o2;"
963
+ " void *addr = &(o2, o1); } " ,
964
+ {" -Wno-unused-value" });
965
+ const auto Results =
966
+ match (withEnclosingCompound (declRefTo (" o1" )), AST->getASTContext ());
967
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
968
+ }
969
+
970
+ TEST (ExprMutationAnalyzerTest, CommaExprAsReturnAsValue) {
971
+ auto AST = buildASTFromCodeWithArgs (" int f() { int x, y; return (x, y); }" ,
972
+ {" -Wno-unused-value" });
973
+ auto Results =
974
+ match (withEnclosingCompound (declRefTo (" y" )), AST->getASTContext ());
975
+ EXPECT_FALSE (isMutated (Results, AST.get ()));
976
+ }
977
+
978
+ TEST (ExprMutationAnalyzerTest, CommaEpxrAsReturnAsNonConstRef) {
979
+ const auto AST =
980
+ buildASTFromCodeWithArgs (" int& f() { int x, y; return (y, x); }" ,
981
+ {" -Wno-unused-value" });
982
+ const auto Results =
983
+ match (withEnclosingCompound (declRefTo (" x" )), AST->getASTContext ());
984
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
985
+ }
986
+
987
+ TEST (ExprMutationAnalyzerTest, CommaExprAsArrayToPointerDecay) {
988
+ const auto AST =
989
+ buildASTFromCodeWithArgs (" void g(int*); "
990
+ " void f() { int x[2], y[2]; g((y, x)); }" ,
991
+ {" -Wno-unused-value" });
992
+ const auto Results =
993
+ match (withEnclosingCompound (declRefTo (" x" )), AST->getASTContext ());
994
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
995
+ }
996
+
997
+ TEST (ExprMutationAnalyzerTest, CommaExprAsUniquePtr) {
998
+ const std::string UniquePtrDef =
999
+ " template <class T> struct UniquePtr {"
1000
+ " UniquePtr();"
1001
+ " UniquePtr(const UniquePtr&) = delete;"
1002
+ " T& operator*() const;"
1003
+ " T* operator->() const;"
1004
+ " };" ;
1005
+ const auto AST = buildASTFromCodeWithArgs (
1006
+ UniquePtrDef + " template <class T> void f() "
1007
+ " { UniquePtr<T> x; UniquePtr<T> y;"
1008
+ " (y, x)->mf(); }" ,
1009
+ {" -fno-delayed-template-parsing -Wno-unused-value" });
1010
+ const auto Results =
1011
+ match (withEnclosingCompound (declRefTo (" x" )), AST->getASTContext ());
1012
+ EXPECT_TRUE (isMutated (Results, AST.get ()));
1013
+ }
1014
+
884
1015
TEST (ExprMutationAnalyzerTest, LambdaDefaultCaptureByValue) {
885
1016
const auto AST = buildASTFromCode (" void f() { int x; [=]() { x; }; }" );
886
1017
const auto Results =
0 commit comments