Summary:
Checker to validate string constructor parameters.
A common mistake is to swap parameter for the fill-constructor.
```
std::string str('x', 4);
std::string str('4', x);
```
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D19146
llvm-svn: 267011
Summary:
Little cleanup to lift-out and to remove some frequently used
ast-matchers.
Some of theses matchers are candidates to be lifted to ASTMatchers.h.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D19200
llvm-svn: 267003
Summary:
Clang-tidy modernize-raw-string-literal check crashes on run-time assert while it is evaluating compiler predefined identifiers such as
- __FUNCTION__
- __func__
- __PRETTY_FUNCTION__
Check is asserting because it cannot find opening quote for such string literal. It occurs only on debug build config.
I think that it would be good to prune such cases by crossing off predefined expressions - there is no need to evaluate such matches.
Reviewers: LegalizeAdulthood, alexfh
Subscribers: cfe-commits
Patch by Marek Jenda!
Differential Revision: http://reviews.llvm.org/D19331
llvm-svn: 266992
Summary:
The goal of this tool is fairly simple, look up unknown identifiers in a
global database and add the corresponding #include line. It accomplishes
this by hooking into Sema as an ExternalSemaSource and responding to typo
correction callbacks. This means we can see the unknown identifier before
it's being munged by error recovery.
This doesn't work perfectly yet as some typo corrections don't emit
callbacks (delayed typos), but I think this is fixable. We also handle
only one include at a time as this is meant to be run directly from
the editing environment eventually. Adding multiple includes at the same
time is tricky because of error recovery.
This version only has a a dummy database, so all you can do is fixing
missing includes of <string>, but the indexer to build a database will
follow soon.
Reviewers: djasper
Subscribers: ioeric, hokein, cfe-commits
Differential Revision: http://reviews.llvm.org/D19314
llvm-svn: 266870
Summary: Fixes a crash in cppcoreguidelines-pro-type-member-init when checking some record types with a constructor without a body. We now check to make sure the constructor has a body before looking for missing members and base initializers.
Patch by Michael Miller!
Reviewers: aaron.ballman, alexfh, hokein
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D19270
llvm-svn: 266862
At the moment almost every lit.site.cfg.in contains two lines comment:
## Autogenerated by LLVM/Clang configuration.
# Do not edit!
The patch adds variable LIT_SITE_CFG_IN_HEADER, that is replaced from
configure_lit_site_cfg with the note and some useful information.
llvm-svn: 266518
Summary:
The string class contains methods which support receiving either a string literal or a string object.
For example, calls to append can receive either a char* or a string.
```
string& append (const string& str);
string& append (const char* s);
```
Which make these cases equivalent, and the .c_str() useless:
```
std::string s = "123";
str.append(s);
str.append(s.c_str());
```
In these cases, removing .c_str() doesn't provide any size or speed improvement.
It's only a readability issue.
If the string contains embedded NUL characters, the string literal and the string
object won't produce the same semantic.
Reviewers: alexfh, sbenza
Subscribers: LegalizeAdulthood, aaron.ballman, chapuni, Eugene.Zelenko, cfe-commits
Differential Revision: http://reviews.llvm.org/D18475
llvm-svn: 266463
Summary:
The check detects multi-statement macros that are used in unbraced conditionals.
Only the first statement will be part of the conditionals and the rest will fall
outside of it and executed unconditionally.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18766
llvm-svn: 266369
Summary: The patch is fixing the generation of clang-tidy documentation.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D19121
llvm-svn: 266333
Summary: Added the remaining features needed to satisfy C++ Core Guideline Type.6: Always initialize a member variable to cppcoreguidelines-pro-type-member-init. The check now flags all default-constructed uses of record types without user-provided default constructors that would leave their memory in an undefined state. The check suggests value initializing them instead.
Reviewers: flx, alexfh, aaron.ballman
Subscribers: klimek, aaron.ballman, LegalizeAdulthood, cfe-commits
Patch by Michael Miller!
Differential Revision: http://reviews.llvm.org/D18584
llvm-svn: 266191
Checks if constructors and assignment operators that are marked '= default' are
actually deleted by the compiler.
Patch by Alex Pilkiewicz!
Differential Revision: http://reviews.llvm.org/D18961
llvm-svn: 266190
Summary:
The Fix-Its for the added test cases were before:
-void F11(const unsigned int /*version*/);
+void F11(unsigned int int /*version*/);
-void F12(const bool b = true);
+void F12(_Bool true);
Reviewers: fowles, hokein, sbenza, alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18993
llvm-svn: 266044
Summary:
This check flags initializers of globals that access extern objects, and therefore can lead to order-of-initialization problems (this recommandation is part of CPP core guidelines).
Note that this only checks half of the guideline for now (it does not enforce using constexpr functions).
Reviewers: aaron.ballman, alexfh
Subscribers: aaron.ballman, etienneb, Eugene.Zelenko, cfe-commits
Patch by Clement Courbet!
Differential Revision: http://reviews.llvm.org/D18649
llvm-svn: 265774
Summary:
This patch adds the support for detecting suspicious string
literals and their //incorrect// usage.
The following example shows a incorrect character escaping leading
to an embedded NUL character.
```
std::string str = "\0x42"; // Should be "\x42".
```
The patch also add detection of truncated literal when a literal
is passed to a string constructor.
Reviewers: hokein, alexfh
Subscribers: LegalizeAdulthood, bcraig, Eugene.Zelenko, bkramer, cfe-commits
Differential Revision: http://reviews.llvm.org/D18783
llvm-svn: 265691
Summary:
This is the same kind of bug than [[ http://reviews.llvm.org/D18238 | D18238 ]].
Fix crashes caused by deferencing null pointer when declarations parsing may be delayed.
The body of the declarations may be null.
The crashes were observed with a Windows build of clang-tidy and the following command-line.
```
command-line switches: -fms-compatibility-version=19 -fms-compatibility
```
Reviewers: alexfh
Subscribers: kimgr, LegalizeAdulthood, cfe-commits
Differential Revision: http://reviews.llvm.org/D18852
llvm-svn: 265681
Going through a string removes some of the smarts of the diagnosic printer
and makes the code more complicated. This change has some cosmetic impact
on the output but that's mostly minor.
llvm-svn: 265680
Summary:
In Release mode, the check was infinite looping over chromium code base.
It seems there is something strange with the creation of the Maps.
I believe the compiler is making some assumption with the implicit conversion from enum <-> int.
By moving the map to a standard switch/cases, we no longer allocate memory and we can keep the same behavior. For a small amount of elements, this is fine.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18833
llvm-svn: 265679
Summary:
Clang-tidy is reporting a warning of redundant string initialisation
on a string parameter initialized with empty string.
See bug: 27087
The reported example is:
```
#include <string>
void fn(std::string a = "");
```
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18829
llvm-svn: 265671
Summary:
The clang-tidy documentation can't be generated because of broken links.
```
Warning, treated as error:
/home/etienneb/llvm/llvm/tools/clang/tools/extra/docs/clang-tidy/checks/google-readability-function-size.rst:: WARNING: document isn't included in any toctree
```
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18803
llvm-svn: 265539
Summary:
Existing checker misc-misplaced-widening-cast was extended:
- New use cases: casted expression as lhs or rhs of a logical comparison or function argument
- New types: beside int, long and long long various char types, short and int128 added
- New option to check implicit casts: forgetting a cast is at least as common and as dangerous as misplacing it. This option can be disabled.
This patch depends on AST Matcher patches D17986 and D18243 and also contains fix for checker misc-bool-pointer-implicit-conversion needed because of the fix in the AST Matcher patch.
Reviewers: hokein, alexfh
Subscribers: o.gyorgy, xazax.hun, cfe-commits
Differential Revision: http://reviews.llvm.org/D17987
llvm-svn: 265532
Summary:
The clang-tidy documentation generation was broken since commit : http://reviews.llvm.org/D18457
I ran locally the documentation generation and I fixed errors related to that specific check.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18764
llvm-svn: 265375
Summary:
This patch is adding detection of common string literal patterns
that should not trigger warnings.
[*] Add a limit on the number of concatenated token,
[*] Add support for parenthese sequence of tokens,
[*] Add detection of valid indentation.
As an example, this code will no longer trigger a warning:
```
const char* Array[] = {
"first literal"
"indented literal"
"indented literal",
"second literal",
[...]
```
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18695
llvm-svn: 265303
Fix for __declspec attributes and const=0 without space
This patch is to address 2 problems I found with Clang-tidy:modernize-use-override.
1: missing spaces on pure function decls.
Orig:
void pure() const=0
Problem:
void pure() constoverride =0
Fixed:
void pure() const override =0
2: This is ms-extension specific, but possibly applies to other attribute types. The override is placed before the attribute which doesn’t work well with declspec as this attribute can be inherited or placed before the method identifier.
Orig:
class __declspec(dllexport) X : public Y
{
void p();
};
Problem:
class override __declspec(dllexport) class X : public Y
{
void p();
};
Fixed:
class __declspec(dllexport) class X : public Y
{
void p() override;
};
Patch by Robert Bolter!
Differential Revision: http://reviews.llvm.org/D18396
llvm-svn: 265298