mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 1475882 - clang-tidy: Enable misc-string-constructor check. r=andi
Finds string constructors that are suspicious and probably errors. There are currently no misc-string-constructor warnings in mozilla-central! https://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-constructor.html MozReview-Commit-ID: LyJt6wqOhg9 --HG-- extra : source : 0b36b6b1b7931adec5846086a52080edb3ec5e7d extra : histedit_source : 30249980b219d4813fc5503c87e84265ad354e2f
This commit is contained in:
parent
59cd83d07a
commit
126761ba3c
@ -54,6 +54,8 @@ clang_checkers:
|
||||
publish: !!bool yes
|
||||
- name: misc-macro-repeated-side-effects
|
||||
publish: !!bool yes
|
||||
- name: misc-string-constructor
|
||||
publish: !!bool yes
|
||||
- name: misc-suspicious-missing-comma
|
||||
publish: !!bool yes
|
||||
- name: misc-suspicious-semicolon
|
||||
|
17
tools/clang-tidy/test/misc-string-constructor.cpp
Normal file
17
tools/clang-tidy/test/misc-string-constructor.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-constructor.html
|
||||
|
||||
#include "structures.h"
|
||||
|
||||
void test()
|
||||
{
|
||||
// A common mistake is to swap parameters to the ‘fill’ string-constructor.
|
||||
std::string str('x', 50); // should be str(50, 'x')
|
||||
|
||||
// Calling the string-literal constructor with a length bigger than the
|
||||
// literal is suspicious and adds extra random characters to the string.
|
||||
std::string("test", 200); // Will include random characters after "test".
|
||||
|
||||
// Creating an empty string from constructors with parameters is considered
|
||||
// suspicious. The programmer should use the empty constructor instead.
|
||||
std::string("test", 0); // Creation of an empty string.
|
||||
}
|
1
tools/clang-tidy/test/misc-string-constructor.json
Normal file
1
tools/clang-tidy/test/misc-string-constructor.json
Normal file
@ -0,0 +1 @@
|
||||
"[[\"warning\", \"string constructor parameters are probably swapped; expecting string(count, character)\", \"misc-string-constructor\"], [\"warning\", \"length is bigger then string literal size\", \"misc-string-constructor\"], [\"warning\", \"constructor creating an empty string\", \"misc-string-constructor\"]]"
|
@ -37,7 +37,9 @@ class basic_string {
|
||||
public:
|
||||
typedef basic_string<T> _Type;
|
||||
basic_string() {}
|
||||
basic_string(const T *p);
|
||||
basic_string(const T *p);
|
||||
basic_string(const T *p, size_t count);
|
||||
basic_string(size_t count, char ch);
|
||||
~basic_string() {}
|
||||
size_t size() const;
|
||||
bool empty() const;
|
||||
|
Loading…
Reference in New Issue
Block a user