[clang-tools-extra] r303849 -
Author: fgross Date: Thu May 25 06:43:06 2017 New Revision: 303849 URL: http://llvm.org/viewvc/llvm-project?rev=303849&view=rev Log: (empty) Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp?rev=303849&r1=303848&r2=303849&view=diff == --- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Thu May 25 06:43:06 2017 @@ -167,7 +167,7 @@ void BracesAroundStatementsCheck::check( } } -/// Find location of right parenthesis closing condition +/// Find location of right parenthesis closing condition. template SourceLocation BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
RE: [clang-tools-extra] r303849 -
Just a commit access test with messed up log message. - Florian -Original Message- From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of Florian Gross via cfe-commits Sent: Thursday, May 25, 2017 1:43 PM To: cfe-commits@lists.llvm.org Subject: [clang-tools-extra] r303849 - Author: fgross Date: Thu May 25 06:43:06 2017 New Revision: 303849 URL: http://llvm.org/viewvc/llvm-project?rev=303849&view=rev Log: (empty) Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp?rev=303849&r1=303848&r2=303849&view=diff == --- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Thu May 25 06:43:06 2017 @@ -167,7 +167,7 @@ void BracesAroundStatementsCheck::check( } } -/// Find location of right parenthesis closing condition +/// Find location of right parenthesis closing condition. template SourceLocation BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r304657 - [clang-tidy] Make misc-static-assert accept assert(!"msg")
Author: fgross Date: Sat Jun 3 05:13:55 2017 New Revision: 304657 URL: http://llvm.org/viewvc/llvm-project?rev=304657&view=rev Log: [clang-tidy] Make misc-static-assert accept assert(!"msg") Added negated string literals to the set of IsAlwaysFalse expressions to avoid flagging of assert(!"msg"). Differential Revision: http://reviews.llvm.org/D33827 Modified: clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp?rev=304657&r1=304656&r2=304657&view=diff == --- clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp Sat Jun 3 05:13:55 2017 @@ -33,9 +33,11 @@ void StaticAssertCheck::registerMatchers if (!(getLangOpts().CPlusPlus11 || getLangOpts().C11)) return; + auto NegatedString = unaryOperator( + hasOperatorName("!"), hasUnaryOperand(ignoringImpCasts(stringLiteral(; auto IsAlwaysFalse = expr(anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)), - cxxNullPtrLiteralExpr(), gnuNullExpr())) + cxxNullPtrLiteralExpr(), gnuNullExpr(), NegatedString)) .bind("isAlwaysFalse"); auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf( IsAlwaysFalse, cStyleCastExpr(has(ignoringParenImpCasts(IsAlwaysFalse))) Modified: clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp?rev=304657&r1=304656&r2=304657&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp Sat Jun 3 05:13:55 2017 @@ -76,6 +76,9 @@ int main() { // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be // CHECK-FIXES: {{^ }}static_assert(ZERO_MACRO, ""); + assert(!"Don't report me!"); + // CHECK-FIXES: {{^ }}assert(!"Don't report me!"); + assert(0 && "Don't report me!"); // CHECK-FIXES: {{^ }}assert(0 && "Don't report me!"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r359801 - Fixed: Duck-typing in readability-redundant-smartptr-get didn't catch MSVC STL smart pointers.
Author: fgross Date: Thu May 2 09:41:28 2019 New Revision: 359801 URL: http://llvm.org/viewvc/llvm-project?rev=359801&view=rev Log: Fixed: Duck-typing in readability-redundant-smartptr-get didn't catch MSVC STL smart pointers. Differential Revision: https://reviews.llvm.org/D61209 Added: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp?rev=359801&r1=359800&r2=359801&view=diff == --- clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp Thu May 2 09:41:28 2019 @@ -30,6 +30,10 @@ internal::Matcher callToGet(const .bind("redundant_get"); } +internal::Matcher knownSmartptr() { + return recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr")); +} + void registerMatchersForGetArrowStart(MatchFinder *Finder, MatchFinder::MatchCallback *Callback) { const auto QuacksLikeASmartptr = recordDecl( @@ -39,21 +43,23 @@ void registerMatchersForGetArrowStart(Ma has(cxxMethodDecl(hasName("operator*"), returns(qualType(references( type().bind("op*Type"))); + // Make sure we are not missing the known standard types. + const auto Smartptr = anyOf(knownSmartptr(), QuacksLikeASmartptr); + // Catch 'ptr.get()->Foo()' - Finder->addMatcher(memberExpr(expr().bind("memberExpr"), isArrow(), -hasObjectExpression(ignoringImpCasts( -callToGet(QuacksLikeASmartptr, - Callback); + Finder->addMatcher( + memberExpr(expr().bind("memberExpr"), isArrow(), + hasObjectExpression(ignoringImpCasts(callToGet(Smartptr, + Callback); // Catch '*ptr.get()' or '*ptr->get()' Finder->addMatcher( - unaryOperator(hasOperatorName("*"), -hasUnaryOperand(callToGet(QuacksLikeASmartptr))), + unaryOperator(hasOperatorName("*"), hasUnaryOperand(callToGet(Smartptr))), Callback); // Catch '!ptr.get()' - const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl( - QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType())); + const auto CallToGetAsBool = ignoringParenImpCasts(callToGet( + recordDecl(Smartptr, has(cxxConversionDecl(returns(booleanType())); Finder->addMatcher( unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)), Callback); @@ -71,10 +77,7 @@ void registerMatchersForGetEquals(MatchF // This one is harder to do with duck typing. // The operator==/!= that we are looking for might be member or non-member, // might be on global namespace or found by ADL, might be a template, etc. - // For now, lets keep a list of known standard types. - - const auto IsAKnownSmartptr = - recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr")); + // For now, lets keep it to the known standard types. // Matches against nullptr. Finder->addMatcher( @@ -82,7 +85,7 @@ void registerMatchersForGetEquals(MatchF hasEitherOperand(ignoringImpCasts( anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(), integerLiteral(equals(0), - hasEitherOperand(callToGet(IsAKnownSmartptr))), + hasEitherOperand(callToGet(knownSmartptr(, Callback); // FIXME: Match and fix if (l.get() == r.get()). Added: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp?rev=359801&view=auto == --- clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp (added) +++ clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp Thu May 2 09:41:28 2019 @@ -0,0 +1,94 @@ +// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t + +#define NULL __null + +namespace std { + +// MSVC headers define operator templates instead of plain operators. + +template +struct unique_ptr { + template + T2& operator*() const; + template + T2* operator->() const; + T* get() const; + explicit operator bool() const noexcept; +}; + +template +struct shared_ptr { + template + T2& operator*() const; + template + T2* operator->() const; + T* get() const; + explicit operat
r310095 - [ASTMatcher] Add handling for DeducedType to HasDeclarationMatcher
Author: fgross Date: Fri Aug 4 11:59:19 2017 New Revision: 310095 URL: http://llvm.org/viewvc/llvm-project?rev=310095&view=rev Log: [ASTMatcher] Add handling for DeducedType to HasDeclarationMatcher HasDeclarationMatcher did not handle DeducedType, it always returned false for deduced types. So with code like this: struct X{}; auto x = X{}; This did no longer match: varDecl(hasType(recordDecl(hasName("X" Because HasDeclarationMatcher didn't resolve the DeducedType of x. Differential Revision: https://reviews.llvm.org/D36308 Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=310095&r1=310094&r2=310095&view=diff == --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Aug 4 11:59:19 2017 @@ -741,24 +741,34 @@ private: /// matcher matches on it. bool matchesSpecialized(const Type &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const { + +// DeducedType does not have declarations of its own, so +// match the deduced type instead. +const Type *EffectiveType = &Node; +if (const auto *S = dyn_cast(&Node)) { + EffectiveType = S->getDeducedType().getTypePtrOrNull(); + if (!EffectiveType) +return false; +} + // First, for any types that have a declaration, extract the declaration and // match on it. -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getInterface(), Finder, Builder); } @@ -770,14 +780,14 @@ private: // template struct X { T t; } class A {}; X a; // The following matcher will match, which otherwise would not: // fieldDecl(hasType(pointerType())). -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesSpecialized(S->getReplacementType(), Finder, Builder); } // For template specialization types, we want to match the template // declaration, as long as the type is still dependent, and otherwise the // declaration of the instantiated tag type. -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { if (!S->isTypeAlias() && S->isSugared()) { // If the template is non-dependent, we want to match the instantiated // tag type. @@ -796,7 +806,7 @@ private: // FIXME: We desugar elaborated types. This makes the assumption that users // do never want to match on whether a type is elaborated - there are // arguments for both sides; for now, continue desugaring. -if (const auto *S = dyn_cast(&Node)) { +if (const auto *S = dyn_cast(EffectiveType)) { return matchesSpecialized(S->desugar(), Finder, Builder); } return false; Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=310095&r1=310094&r2=310095&view=diff == --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Fri Aug 4 11:59:19 2017 @@ -1184,6 +1184,10 @@ TEST(TypeMatching, MatchesAutoTypes) { EXPECT_TRUE(matches("int v[] = { 2, 3 }; void f() { for (int i : v) {} }", autoType())); + EXPECT_TRUE(matches("auto i = 2;", varDecl(hasType(isInteger(); + EXPECT_TRUE(matches("struct X{}; auto x = X{};", + varDecl(hasType(recordDecl(hasName("X")); + // FIXME: Matching against the type-as-written can't work here, because the //type as written was not deduced. //EXPECT_TRUE(matches("auto a = 1;", __
[clang-tools-extra] r310096 - [clang-tidy] Added clang-tidy test cases related to rL310095
Author: fgross Date: Fri Aug 4 12:01:56 2017 New Revision: 310096 URL: http://llvm.org/viewvc/llvm-project?rev=310096&view=rev Log: [clang-tidy] Added clang-tidy test cases related to rL310095 Differential Revision: https://reviews.llvm.org/D36308 Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-string-concatenation.cpp clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp clang-tools-extra/trunk/test/clang-tidy/readability-uniqueptr-delete-release.cpp Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp?rev=310096&r1=310095&r2=310096&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp Fri Aug 4 12:01:56 2017 @@ -723,6 +723,11 @@ void standardContainerClearIsReinit() { std::move(container); container.clear(); container.empty(); + +auto container2 = container; +std::move(container2); +container2.clear(); +container2.empty(); } { std::deque container; Modified: clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-string-concatenation.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-string-concatenation.cpp?rev=310096&r1=310095&r2=310096&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-string-concatenation.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-string-concatenation.cpp Fri Aug 4 12:01:56 2017 @@ -19,6 +19,8 @@ std::string g(std::string) {} int main() { std::string mystr1, mystr2; std::wstring mywstr1, mywstr2; + auto myautostr1 = mystr1; + auto myautostr2 = mystr2; for (int i = 0; i < 10; ++i) { f(mystr1 + mystr2 + mystr1); @@ -33,6 +35,8 @@ int main() { // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation mywstr1 = mywstr2 + mywstr2 + mywstr2; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: string concatenation +myautostr1 = myautostr1 + myautostr2; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation mywstr1 = mywstr2 + mywstr2; mystr1 = mystr2 + mystr2; Modified: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp?rev=310096&r1=310095&r2=310096&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get.cpp Fri Aug 4 12:01:56 2017 @@ -97,6 +97,12 @@ void Positive() { // CHECK-MESSAGES: int i = *ip.get(); // CHECK-FIXES: int i = *ip; + auto ip2 = ip; + i = *ip2.get(); + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call + // CHECK-MESSAGES: i = *ip2.get(); + // CHECK-FIXES: i = *ip2; + std::unique_ptr uu; std::shared_ptr *ss; bool bb = uu.get() == nullptr; Modified: clang-tools-extra/trunk/test/clang-tidy/readability-uniqueptr-delete-release.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-uniqueptr-delete-release.cpp?rev=310096&r1=310095&r2=310096&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/readability-uniqueptr-delete-release.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/readability-uniqueptr-delete-release.cpp Fri Aug 4 12:01:56 2017 @@ -24,6 +24,11 @@ void Positives() { // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects [readability-uniqueptr-delete-release] // CHECK-FIXES: {{^}} P = nullptr; + auto P2 = P; + delete P2.release(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects [readability-uniqueptr-delete-release] + // CHECK-FIXES: {{^}} P2 = nullptr; + std::unique_ptr Array[20]; delete Array[4].release(); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits