summaryrefslogtreecommitdiff
path: root/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2019-01-16 08:36:23 +0000
committerClement Courbet <courbet@google.com>2019-01-16 08:36:23 +0000
commite45f563c497e336fd1accb0c11bf7d95f36f4b80 (patch)
tree10b764b93b47f2890481627175e68fbb4877de94 /clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp
parentba595fda49ec5e4db6d3f8d90804f2e601272799 (diff)
[clang-tidy] bugprone-string-constructor: Catch string from nullptr.
Summary: Context: https://twitter.com/willkirkby/status/1084219580799741953 Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D56657
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp b/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp
index 51d91305882..3ab4f424087 100644
--- a/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp
+++ b/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp
@@ -9,6 +9,7 @@ template <typename C, typename T = std::char_traits<C>, typename A = std::alloca
struct basic_string {
basic_string();
basic_string(const C*, unsigned int size);
+ basic_string(const C *, const A &allocator = A());
basic_string(unsigned int size, C c);
};
typedef basic_string<char> string;
@@ -45,6 +46,15 @@ void Test() {
// CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
std::string q5(kText3, 0x1000000);
// CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
+ std::string q6(nullptr);
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructing string from nullptr is undefined behaviour
+ std::string q7 = 0;
+ // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr is undefined behaviour
+}
+
+std::string StringFromZero() {
+ return 0;
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr is undefined behaviour
}
void Valid() {
@@ -53,4 +63,5 @@ void Valid() {
std::wstring wstr(4, L'x');
std::string s1("test", 4);
std::string s2("test", 3);
+ std::string s3("test");
}