Summary:
The current checker is able to recognize std::string but does not recognize other string variants.
This patch is adding the support for any string defined with basic_string without considering the
the underlying char type.
The most common variant is: 'std::wstring' based on 'wchar_t'.
There are also other string variants added to the standard: u16string, u32string, etc...
Reviewers: alexfh
Subscribers: mamai, dblaikie, cfe-commits
Differential Revision: http://reviews.llvm.org/D18412
llvm-svn: 264325
The return value of every assign operator should be Type&, not only for copy and move assign operators.
Patch by Adam Balogh!
Reviewers: hokein, alexfh
Differential Revision: http://reviews.llvm.org/D18264
llvm-svn: 264251
Summary: Extends the UnnecessaryCopyInitialization to detect copies of local variables and parameters that are unneeded.
Patch by Matt Kulukundis!
Reviewers: alexfh, hokein
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18149
llvm-svn: 264146
Summary:
There is a silly bug that got introduced after fixing incorrect paths with this patch:
http://reviews.llvm.org/D18293
The tests was present twice in the file.
Reviewers: alexfh, rnk
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18365
llvm-svn: 264080
Summary:
The string constructors are not defined using optional parameters and are not recognize by the checker.
The constructor defined in the MSVC header is defined with 1 parameter. Therefore, patterns are not recognized by the checker.
The current patch add support to accept constructor with only one parameter.
Repro on a Visual Studio 14 installation with the following code:
```
void f1(const std::string &s) {
f1(s.c_str());
}
```
In the xstring.h header, the constructors are defined this way:
```
basic_string(const _Myt& _Right) [...]
basic_string(const _Myt& _Right, const _Alloc& _Al) [...]
```
The CXXConstructExpr to recognize only contains 1 parameter.
```
CXXConstructExpr 0x3f1a070 <C:\src\llvm\examples\test.cc:6:6, col:14> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class
std::allocator<char> >' 'void (const char *) __attribute__((thiscall))'
`-CXXMemberCallExpr 0x3f1a008 <col:6, col:14> 'const char *'
`-MemberExpr 0x3f19fe0 <col:6, col:8> '<bound member function type>' .c_str 0x3cc22f8
`-DeclRefExpr 0x3f19fc8 <col:6> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >' lvalue ParmVar 0x3f19c80 's' 'const std::string &'
```
Reviewers: aaron.ballman, alexfh
Subscribers: aemerson
Differential Revision: http://reviews.llvm.org/D18285
llvm-svn: 264075
Summary:
Invalid source location are causing clang-tidy to crash when manipulating an invalid file.
Macro definitions on the command line have locations in a virtual buffer and therefore
don't have a corresponding valid FilePath.
A recent patch added path conversion to absolute path. As the FilePath may now be empty,
the result of makeAbsolutePath may incorrectly be the folder WorkingDir. The crash occurs
in getLocation which is not able to find the appropriate FileEntry (null pointer).
```
SmallString<128> FixAbsoluteFilePath = Fix.getFilePath();
Files.makeAbsolutePath(FixAbsoluteFilePath);
FixLoc = getLocation(FixAbsoluteFilePath, Fix.getOffset());
```
With relative path, the code was not crashing because getLocation was skipping empty path.
Example of code:
```
int main() { return X; }
```
With the given command-line:
```
clang-tidy test.cc --checks=misc-macro-* -- -DX=0+0
```
Reviewers: alexfh, aaron.ballman
Subscribers: aaron.ballman, cfe-commits
Differential Revision: http://reviews.llvm.org/D18262
llvm-svn: 264073
Summary:
The string constructors are not defined using optional parameters and are not recognized by the redundant-string-init checker.
The following patch fixes the redundant-string-init checker for the Visual Studio 14 headers file.
The matcher now accept both variant (with 1 and 2 parameters).
Also added new unittests.
Similar issue than: [[ http://reviews.llvm.org/D18285 | review ]]
In the xstring.h header, the constructors are defined this way:
```
basic_string(const _Myt& _Right) [...]
basic_string(const _Myt& _Right, const _Alloc& _Al) [...]
```
Reviewers: alexfh, hokein
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18293
llvm-svn: 264069
matchesName() uses regular expressions and it is very slow.
hasAnyName() gives the same result and it is much faster.
A benchmark (with all the checks enabled) shows a ~5% speed up of
clang-tidy.
llvm-svn: 263822
Summary:
Fix assertion failure: "Name is not a simple identifier".
`Decl::GetName` assumes the name should be an identifier. When the check
processes the function calling statement with speciail key name like
'it.operator->()', it will trigger the assert in `GetName`.
Rather than using `Decl::GetName`, we use `getNameAsString` which works
with special key names in C++.
Reviewers: bkramer
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18141
llvm-svn: 263426
Summary:
Move code shared between UnnecessaryCopyInitialization and ForRangeCopyCheck into utilities files.
Add more test cases for UnnecessaryCopyInitialization and disable fixes inside of macros.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D17488
llvm-svn: 262781
This doesn't really do much at the moment. You can load it via libclang
and set the -checks via an extra command line argument as illustrated in
the test case. Support for other options (including headers check) is
currently missing. Also when using this with libclang some checks may
not work with the precompiled preamble in place.
This can be used to easily show clang-tidy warnings in an editor
integration as all that's needed is adding command line flags that are
passed into libclang. Warnings and FixIts are exposed via the existing
CXDiagnostic machinery.
Differential Revision: http://reviews.llvm.org/D17807
llvm-svn: 262595
It was failing to build with:
clang-tidy\readability\IdentifierNamingCheck.cpp(640):
error C2882: 'format' : illegal use of namespace identifier in expression
llvm-svn: 262257
Summary:
The clang-tidy will trigger an assertion if it's not in the building directory.
TEST:
cd <llvm-repo>/
./build/bin/clang-tidy --checks=-*,modernize-use-nullptr -p build tools/clang/tools/extra/clang-tidy/ClangTidy.cpp
The crash issue is gone after applying this patch.
Fixes PR24834, PR26241
Reviewers: bkramer, alexfh
Subscribers: rizsotto.mailinglist, cfe-commits
Differential Revision: http://reviews.llvm.org/D17335
llvm-svn: 261991
Summary: Because of the recent Google Code shutdown links to the Google Code Style up there are no longer relevant.
Reviewers: alexfh, hokein
Subscribers: cfe-commits
Patch by Kirill Bobyrev!
Differential Revision: http://reviews.llvm.org/D17602
llvm-svn: 261868
For now, it just detects that host is non-Windows and target is msvc.
FIXME: It should be probable for cross compilations. Detect whether target's headers would be available.
llvm-svn: 261814
Summary:
This patch introduces the modernize-deprecated-headers check, which is supposed to replace deprecated C library headers with the C++ STL-ones.
For information see documentation; for exmaples see the test cases.
Reviewers: Eugene.Zelenko, LegalizeAdulthood, alexfh
Subscribers: cfe-commits
Patch by Kirill Bobyrev!
Differential Revision: http://reviews.llvm.org/D17484
llvm-svn: 261738
Adds a new check "misc-forward-declaration-namespace".
In check, A forward declaration is considerred in a potentially wrong namespace
if there is any definition/declaration with the same name exists in a different
namespace.
Reviewers: akuegel, hokein, alexfh
Patch by Eric Liu!
Differential Revision: http://reviews.llvm.org/D17195
llvm-svn: 261737
instead of a get() method we find in the class.
The duck typed smart pointer class could have overloaded get() methods
and we should only skip the one that matches.
llvm-svn: 261102