summaryrefslogtreecommitdiff
path: root/Utilities/ClangTidyModule/Tests
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-11-16 09:44:29 -0500
committerKyle Edwards <kyle.edwards@kitware.com>2022-11-18 09:37:58 -0500
commitc6368a23feae261bfce4beaf0b4fca4c5c56677e (patch)
tree69412cde4b192269f361dcff3a343a19189574b0 /Utilities/ClangTidyModule/Tests
parent0784261a6808989bd9fed9f7f30ac5ac00be8bf6 (diff)
downloadcmake-c6368a23feae261bfce4beaf0b4fca4c5c56677e.tar.gz
clang-tidy module: look for sizeof string literal in cmStrLen() check
Diffstat (limited to 'Utilities/ClangTidyModule/Tests')
-rw-r--r--Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-fixit.cxx5
-rw-r--r--Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-stdout.txt32
-rw-r--r--Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen.cxx5
3 files changed, 42 insertions, 0 deletions
diff --git a/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-fixit.cxx b/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-fixit.cxx
index c93d5576fb..cde00864f1 100644
--- a/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-fixit.cxx
+++ b/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-fixit.cxx
@@ -27,11 +27,16 @@ int main()
(void)cmStrLen("Goodbye");
(void)cmStrLen("Hola");
(void)cmStrLen("Bonjour");
+ (void)(cmStrLen("Hallo"));
+ (void)(4 + cmStrLen("Hallo"));
+ (void)(cmStrLen("Hallo"));
+ (void)(4 + cmStrLen("Hallo"));
// No correction needed
(void)ns2::strlen("Salve");
(void)cmStrLen("Konnichiwa");
(void)strlen(s0);
+ (void)(sizeof("Hallo") - 2);
return 0;
}
diff --git a/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-stdout.txt b/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-stdout.txt
index 6c52ad5af9..d18822a4f4 100644
--- a/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-stdout.txt
+++ b/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen-stdout.txt
@@ -18,3 +18,35 @@ cmake-use-cmstrlen.cxx:29:9: warning: use cmStrLen() for string literals [cmake-
^~~~~~~~~~~
cmStrLen
cmake-use-cmstrlen.cxx:29:9: note: FIX-IT applied suggested code changes
+cmake-use-cmstrlen.cxx:30:10: warning: use cmStrLen() for string literals [cmake-use-cmstrlen]
+ (void)(sizeof("Hallo") - 1);
+ ^~~~~~ ~~~
+ cmStrLen
+cmake-use-cmstrlen.cxx:30:10: note: FIX-IT applied suggested code changes
+cmake-use-cmstrlen.cxx:30:26: note: FIX-IT applied suggested code changes
+ (void)(sizeof("Hallo") - 1);
+ ^
+cmake-use-cmstrlen.cxx:31:14: warning: use cmStrLen() for string literals [cmake-use-cmstrlen]
+ (void)(4 + sizeof("Hallo") - 1);
+ ^~~~~~ ~~~
+ cmStrLen
+cmake-use-cmstrlen.cxx:31:14: note: FIX-IT applied suggested code changes
+cmake-use-cmstrlen.cxx:31:30: note: FIX-IT applied suggested code changes
+ (void)(4 + sizeof("Hallo") - 1);
+ ^
+cmake-use-cmstrlen.cxx:32:10: warning: use cmStrLen() for string literals [cmake-use-cmstrlen]
+ (void)(sizeof "Hallo" - 1);
+ ^~~~~~ ~~~
+ cmStrLen( )
+cmake-use-cmstrlen.cxx:32:10: note: FIX-IT applied suggested code changes
+cmake-use-cmstrlen.cxx:32:25: note: FIX-IT applied suggested code changes
+ (void)(sizeof "Hallo" - 1);
+ ^
+cmake-use-cmstrlen.cxx:33:14: warning: use cmStrLen() for string literals [cmake-use-cmstrlen]
+ (void)(4 + sizeof "Hallo" - 1);
+ ^~~~~~ ~~~
+ cmStrLen( )
+cmake-use-cmstrlen.cxx:33:14: note: FIX-IT applied suggested code changes
+cmake-use-cmstrlen.cxx:33:29: note: FIX-IT applied suggested code changes
+ (void)(4 + sizeof "Hallo" - 1);
+ ^
diff --git a/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen.cxx b/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen.cxx
index f36262b5ea..205bc9cc85 100644
--- a/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen.cxx
+++ b/Utilities/ClangTidyModule/Tests/cmake-use-cmstrlen.cxx
@@ -27,11 +27,16 @@ int main()
(void)::strlen("Goodbye");
(void)std::strlen("Hola");
(void)ns1::strlen("Bonjour");
+ (void)(sizeof("Hallo") - 1);
+ (void)(4 + sizeof("Hallo") - 1);
+ (void)(sizeof "Hallo" - 1);
+ (void)(4 + sizeof "Hallo" - 1);
// No correction needed
(void)ns2::strlen("Salve");
(void)cmStrLen("Konnichiwa");
(void)strlen(s0);
+ (void)(sizeof("Hallo") - 2);
return 0;
}