riccibruno created this revision. riccibruno added a reviewer: rsmith. riccibruno added a project: clang. Herald added a subscriber: cfe-commits.
`SequenceChecker` is currently not visiting default arguments and therefore missing cases like: int a; int foo(int x = a++, int y = a); void test() { foo(); // should warn foo(a++); // idem } Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D81003 Files: clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/warn-unsequenced.cpp Index: clang/test/SemaCXX/warn-unsequenced.cpp =================================================================== --- clang/test/SemaCXX/warn-unsequenced.cpp +++ clang/test/SemaCXX/warn-unsequenced.cpp @@ -268,6 +268,36 @@ // cxx17-warning@-1 {{unsequenced modification and access to 'pf'}} } +namespace default_arg { + int a; + void f1(int = a, int = a++); // cxx11-warning 2{{unsequenced modification and access to 'a'}} + // cxx17-warning@-1 2{{unsequenced modification and access to 'a'}} + + void f2(int = a++, int = a); // cxx11-warning {{unsequenced modification and access to 'a'}} + // cxx17-warning@-1 {{unsequenced modification and access to 'a'}} + + void f3(int = a++, int = sizeof(a)); + + void test() { + // TODO: Consider adding a remark indicating the function call where + // the default argument was used. + int b; + f1(); + f1(a); + f1(a,a); // ok + f1(b); // ok + f1(b,a++); // ok + + f2(); + f2(a); // ok + f2(a++); // cxx11-warning {{unsequenced modification and access to 'a'}} + // cxx17-warning@-1 {{unsequenced modification and access to 'a'}} + + f3(); // ok + f3(a++); // ok + } +} + namespace PR20819 { struct foo { void bar(int); }; foo get_foo(int); Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -12977,6 +12977,10 @@ }); } + void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *DAE) { + Visit(DAE->getExpr()); + } + void VisitCXXConstructExpr(const CXXConstructExpr *CCE) { // This is a call, so all subexpressions are sequenced before the result. SequencedSubexpression Sequenced(*this);
Index: clang/test/SemaCXX/warn-unsequenced.cpp =================================================================== --- clang/test/SemaCXX/warn-unsequenced.cpp +++ clang/test/SemaCXX/warn-unsequenced.cpp @@ -268,6 +268,36 @@ // cxx17-warning@-1 {{unsequenced modification and access to 'pf'}} } +namespace default_arg { + int a; + void f1(int = a, int = a++); // cxx11-warning 2{{unsequenced modification and access to 'a'}} + // cxx17-warning@-1 2{{unsequenced modification and access to 'a'}} + + void f2(int = a++, int = a); // cxx11-warning {{unsequenced modification and access to 'a'}} + // cxx17-warning@-1 {{unsequenced modification and access to 'a'}} + + void f3(int = a++, int = sizeof(a)); + + void test() { + // TODO: Consider adding a remark indicating the function call where + // the default argument was used. + int b; + f1(); + f1(a); + f1(a,a); // ok + f1(b); // ok + f1(b,a++); // ok + + f2(); + f2(a); // ok + f2(a++); // cxx11-warning {{unsequenced modification and access to 'a'}} + // cxx17-warning@-1 {{unsequenced modification and access to 'a'}} + + f3(); // ok + f3(a++); // ok + } +} + namespace PR20819 { struct foo { void bar(int); }; foo get_foo(int); Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -12977,6 +12977,10 @@ }); } + void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *DAE) { + Visit(DAE->getExpr()); + } + void VisitCXXConstructExpr(const CXXConstructExpr *CCE) { // This is a call, so all subexpressions are sequenced before the result. SequencedSubexpression Sequenced(*this);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits