[clang-tools-extra] r318916 - [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 23 05:49:14 PST 2017
Author: alexfh
Date: Thu Nov 23 05:49:14 2017
New Revision: 318916
URL: http://llvm.org/viewvc/llvm-project?rev=318916&view=rev
Log:
[clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor
Summary:
Rename misc-string-constructor to bugprone-string-constructor +
manually update the lenght of '==='s in the doc file.
Reviewers: hokein, xazax.hun
Reviewed By: hokein, xazax.hun
Subscribers: mgorny, xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D40388
Added:
clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
- copied, changed from r318913, clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h
- copied, changed from r318913, clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst
- copied, changed from r318913, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
- copied, changed from r318913, clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=318916&r1=318915&r2=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Nov 23 05:49:14 2017
@@ -13,6 +13,7 @@
#include "CopyConstructorInitCheck.h"
#include "IntegerDivisionCheck.h"
#include "MisplacedOperatorInStrlenInAllocCheck.h"
+#include "StringConstructorCheck.h"
#include "SuspiciousMemsetUsageCheck.h"
#include "UndefinedMemoryManipulationCheck.h"
@@ -29,6 +30,8 @@ public:
"bugprone-integer-division");
CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
"bugprone-misplaced-operator-in-strlen-in-alloc");
+ CheckFactories.registerCheck<StringConstructorCheck>(
+ "bugprone-string-constructor");
CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
"bugprone-suspicious-memset-usage");
CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=318916&r1=318915&r2=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Nov 23 05:49:14 2017
@@ -5,6 +5,7 @@ add_clang_library(clangTidyBugproneModul
CopyConstructorInitCheck.cpp
IntegerDivisionCheck.cpp
MisplacedOperatorInStrlenInAllocCheck.cpp
+ StringConstructorCheck.cpp
SuspiciousMemsetUsageCheck.cpp
UndefinedMemoryManipulationCheck.cpp
Copied: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp (from r318913, clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp&r1=318913&r2=318916&rev=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp Thu Nov 23 05:49:14 2017
@@ -16,7 +16,7 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
return Node.getValue().getZExtValue() > N;
@@ -129,6 +129,6 @@ void StringConstructorCheck::check(const
}
}
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
Copied: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h (from r318913, clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h?p2=clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h&r1=318913&r2=318916&rev=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.h Thu Nov 23 05:49:14 2017
@@ -7,19 +7,19 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_CONSTRUCTOR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_CONSTRUCTOR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRING_CONSTRUCTOR_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRING_CONSTRUCTOR_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
/// Finds suspicious string constructor and check their parameters.
///
/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-string-constructor.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-constructor.html
class StringConstructorCheck : public ClangTidyCheck {
public:
StringConstructorCheck(StringRef Name, ClangTidyContext *Context);
@@ -32,8 +32,8 @@ private:
const unsigned int LargeLengthThreshold;
};
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_CONSTRUCTOR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRING_CONSTRUCTOR_H
Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=318916&r1=318915&r2=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Thu Nov 23 05:49:14 2017
@@ -31,7 +31,6 @@ add_clang_library(clangTidyMiscModule
SizeofExpressionCheck.cpp
StaticAssertCheck.cpp
StringCompareCheck.cpp
- StringConstructorCheck.cpp
StringIntegerAssignmentCheck.cpp
StringLiteralWithEmbeddedNulCheck.cpp
SuspiciousEnumUsageCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=318916&r1=318915&r2=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Thu Nov 23 05:49:14 2017
@@ -38,7 +38,6 @@
#include "SizeofExpressionCheck.h"
#include "StaticAssertCheck.h"
#include "StringCompareCheck.h"
-#include "StringConstructorCheck.h"
#include "StringIntegerAssignmentCheck.h"
#include "StringLiteralWithEmbeddedNulCheck.h"
#include "SuspiciousEnumUsageCheck.h"
@@ -114,8 +113,6 @@ public:
"misc-sizeof-expression");
CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
CheckFactories.registerCheck<StringCompareCheck>("misc-string-compare");
- CheckFactories.registerCheck<StringConstructorCheck>(
- "misc-string-constructor");
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
"misc-string-integer-assignment");
CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
Removed: clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp?rev=318915&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp (removed)
@@ -1,134 +0,0 @@
-//===--- StringConstructorCheck.cpp - clang-tidy---------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "StringConstructorCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Tooling/FixIt.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
- return Node.getValue().getZExtValue() > N;
-}
-
-StringConstructorCheck::StringConstructorCheck(StringRef Name,
- ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context),
- WarnOnLargeLength(Options.get("WarnOnLargeLength", 1) != 0),
- LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x800000)) {}
-
-void StringConstructorCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
- Options.store(Opts, "WarnOnLargeLength", WarnOnLargeLength);
- Options.store(Opts, "LargeLengthThreshold", LargeLengthThreshold);
-}
-
-void StringConstructorCheck::registerMatchers(MatchFinder *Finder) {
- if (!getLangOpts().CPlusPlus)
- return;
-
- const auto ZeroExpr = expr(ignoringParenImpCasts(integerLiteral(equals(0))));
- const auto CharExpr = expr(ignoringParenImpCasts(characterLiteral()));
- const auto NegativeExpr = expr(ignoringParenImpCasts(
- unaryOperator(hasOperatorName("-"),
- hasUnaryOperand(integerLiteral(unless(equals(0)))))));
- const auto LargeLengthExpr = expr(ignoringParenImpCasts(
- integerLiteral(isBiggerThan(LargeLengthThreshold))));
- const auto CharPtrType = type(anyOf(pointerType(), arrayType()));
-
- // Match a string-literal; even through a declaration with initializer.
- const auto BoundStringLiteral = stringLiteral().bind("str");
- const auto ConstStrLiteralDecl = varDecl(
- isDefinition(), hasType(constantArrayType()), hasType(isConstQualified()),
- hasInitializer(ignoringParenImpCasts(BoundStringLiteral)));
- const auto ConstPtrStrLiteralDecl = varDecl(
- isDefinition(),
- hasType(pointerType(pointee(isAnyCharacter(), isConstQualified()))),
- hasInitializer(ignoringParenImpCasts(BoundStringLiteral)));
- const auto ConstStrLiteral = expr(ignoringParenImpCasts(anyOf(
- BoundStringLiteral, declRefExpr(hasDeclaration(anyOf(
- ConstPtrStrLiteralDecl, ConstStrLiteralDecl))))));
-
- // Check the fill constructor. Fills the string with n consecutive copies of
- // character c. [i.e string(size_t n, char c);].
- Finder->addMatcher(
- cxxConstructExpr(
- hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
- hasArgument(0, hasType(qualType(isInteger()))),
- hasArgument(1, hasType(qualType(isInteger()))),
- anyOf(
- // Detect the expression: string('x', 40);
- hasArgument(0, CharExpr.bind("swapped-parameter")),
- // Detect the expression: string(0, ...);
- hasArgument(0, ZeroExpr.bind("empty-string")),
- // Detect the expression: string(-4, ...);
- hasArgument(0, NegativeExpr.bind("negative-length")),
- // Detect the expression: string(0x1234567, ...);
- hasArgument(0, LargeLengthExpr.bind("large-length"))))
- .bind("constructor"),
- this);
-
- // Check the literal string constructor with char pointer and length
- // parameters. [i.e. string (const char* s, size_t n);]
- Finder->addMatcher(
- cxxConstructExpr(
- hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
- hasArgument(0, hasType(CharPtrType)),
- hasArgument(1, hasType(isInteger())),
- anyOf(
- // Detect the expression: string("...", 0);
- hasArgument(1, ZeroExpr.bind("empty-string")),
- // Detect the expression: string("...", -4);
- hasArgument(1, NegativeExpr.bind("negative-length")),
- // Detect the expression: string("lit", 0x1234567);
- hasArgument(1, LargeLengthExpr.bind("large-length")),
- // Detect the expression: string("lit", 5)
- allOf(hasArgument(0, ConstStrLiteral.bind("literal-with-length")),
- hasArgument(1, ignoringParenImpCasts(
- integerLiteral().bind("int"))))))
- .bind("constructor"),
- this);
-}
-
-void StringConstructorCheck::check(const MatchFinder::MatchResult &Result) {
- const ASTContext &Ctx = *Result.Context;
- const auto *E = Result.Nodes.getNodeAs<CXXConstructExpr>("constructor");
- assert(E && "missing constructor expression");
- SourceLocation Loc = E->getLocStart();
-
- if (Result.Nodes.getNodeAs<Expr>("swapped-parameter")) {
- const Expr *P0 = E->getArg(0);
- const Expr *P1 = E->getArg(1);
- diag(Loc, "string constructor parameters are probably swapped;"
- " expecting string(count, character)")
- << tooling::fixit::createReplacement(*P0, *P1, Ctx)
- << tooling::fixit::createReplacement(*P1, *P0, Ctx);
- } else if (Result.Nodes.getNodeAs<Expr>("empty-string")) {
- diag(Loc, "constructor creating an empty string");
- } else if (Result.Nodes.getNodeAs<Expr>("negative-length")) {
- diag(Loc, "negative value used as length parameter");
- } else if (Result.Nodes.getNodeAs<Expr>("large-length")) {
- if (WarnOnLargeLength)
- diag(Loc, "suspicious large length parameter");
- } else if (Result.Nodes.getNodeAs<Expr>("literal-with-length")) {
- const auto *Str = Result.Nodes.getNodeAs<StringLiteral>("str");
- const auto *Lit = Result.Nodes.getNodeAs<IntegerLiteral>("int");
- if (Lit->getValue().ugt(Str->getLength())) {
- diag(Loc, "length is bigger then string literal size");
- }
- }
-}
-
-} // namespace misc
-} // namespace tidy
-} // namespace clang
Removed: clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h?rev=318915&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.h (removed)
@@ -1,39 +0,0 @@
-//===--- StringConstructorCheck.h - clang-tidy-------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_CONSTRUCTOR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_CONSTRUCTOR_H
-
-#include "../ClangTidy.h"
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-/// Finds suspicious string constructor and check their parameters.
-///
-/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-string-constructor.html
-class StringConstructorCheck : public ClangTidyCheck {
-public:
- StringConstructorCheck(StringRef Name, ClangTidyContext *Context);
- void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
- void registerMatchers(ast_matchers::MatchFinder *Finder) override;
- void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-
-private:
- const bool WarnOnLargeLength;
- const unsigned int LargeLengthThreshold;
-};
-
-} // namespace misc
-} // namespace tidy
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_CONSTRUCTOR_H
Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=318916&r1=318915&r2=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Nov 23 05:49:14 2017
@@ -57,6 +57,9 @@ The improvements are...
Improvements to clang-tidy
--------------------------
+- The 'misc-string-constructor' check was renamed to `bugprone-string-constructor
+ <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-constructor.html>`_
+
- New `google-avoid-throwing-objc-exception
<http://clang.llvm.org/extra/clang-tidy/checks/google-objc-avoid-throwing-exception.html>`_ check
Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst (from r318913, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst&r1=318913&r2=318916&rev=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-constructor.rst Thu Nov 23 05:49:14 2017
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - misc-string-constructor
+.. title:: clang-tidy - bugprone-string-constructor
-misc-string-constructor
-=======================
+bugprone-string-constructor
+===========================
Finds string constructors that are suspicious and probably errors.
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=318916&r1=318915&r2=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Nov 23 05:49:14 2017
@@ -20,6 +20,7 @@ Clang-Tidy Checks
bugprone-copy-constructor-init
bugprone-integer-division
bugprone-misplaced-operator-in-strlen-in-alloc
+ bugprone-string-constructor
bugprone-suspicious-memset-usage
bugprone-undefined-memory-manipulation
cert-dcl03-c (redirects to misc-static-assert) <cert-dcl03-c>
@@ -132,7 +133,6 @@ Clang-Tidy Checks
misc-sizeof-expression
misc-static-assert
misc-string-compare
- misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
misc-suspicious-enum-usage
Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst?rev=318915&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst (removed)
@@ -1,44 +0,0 @@
-.. title:: clang-tidy - misc-string-constructor
-
-misc-string-constructor
-=======================
-
-Finds string constructors that are suspicious and probably errors.
-
-A common mistake is to swap parameters to the 'fill' string-constructor.
-
-Examples:
-
-.. code-block:: c++
-
- 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.
-
-Examples:
-
-.. code-block:: c++
-
- 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.
-
-Examples:
-
-.. code-block:: c++
-
- std::string("test", 0); // Creation of an empty string.
-
-Options
--------
-
-.. option:: WarnOnLargeLength
-
- When non-zero, the check will warn on a string with a length greater than
- `LargeLengthThreshold`. Default is `1`.
-
-.. option:: LargeLengthThreshold
-
- An integer specifying the large length threshold. Default is `0x800000`.
Copied: clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp (from r318913, clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp&r1=318913&r2=318916&rev=318916&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp Thu Nov 23 05:49:14 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-string-constructor %t
+// RUN: %check_clang_tidy %s bugprone-string-constructor %t
namespace std {
template <typename T>
@@ -21,7 +21,7 @@ extern const char kText3[];
void Test() {
std::string str('x', 4);
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [misc-string-constructor]
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [bugprone-string-constructor]
// CHECK-FIXES: std::string str(4, 'x');
std::wstring wstr(L'x', 4);
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped
Removed: clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp?rev=318915&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp (removed)
@@ -1,56 +0,0 @@
-// RUN: %check_clang_tidy %s misc-string-constructor %t
-
-namespace std {
-template <typename T>
-class allocator {};
-template <typename T>
-class char_traits {};
-template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C> >
-struct basic_string {
- basic_string();
- basic_string(const C*, unsigned int size);
- basic_string(unsigned int size, C c);
-};
-typedef basic_string<char> string;
-typedef basic_string<wchar_t> wstring;
-}
-
-const char* kText = "";
-const char kText2[] = "";
-extern const char kText3[];
-
-void Test() {
- std::string str('x', 4);
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [misc-string-constructor]
- // CHECK-FIXES: std::string str(4, 'x');
- std::wstring wstr(L'x', 4);
- // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped
- // CHECK-FIXES: std::wstring wstr(4, L'x');
- std::string s0(0, 'x');
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
- std::string s1(-4, 'x');
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
- std::string s2(0x1000000, 'x');
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
-
- std::string q0("test", 0);
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
- std::string q1(kText, -4);
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
- std::string q2("test", 200);
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
- std::string q3(kText, 200);
- // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
- std::string q4(kText2, 200);
- // 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
-}
-
-void Valid() {
- std::string empty();
- std::string str(4, 'x');
- std::wstring wstr(4, L'x');
- std::string s1("test", 4);
- std::string s2("test", 3);
-}
More information about the cfe-commits
mailing list