[clang-tools-extra] r347671 - [clang-tidy] Ignore bool -> single bit bitfield conversion in readability-implicit-bool-conversion

2018-11-27 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Nov 27 08:23:39 2018
New Revision: 347671

URL: http://llvm.org/viewvc/llvm-project?rev=347671&view=rev
Log:
[clang-tidy] Ignore bool -> single bit bitfield conversion in 
readability-implicit-bool-conversion

Summary: There is no ambiguity / information loss in this conversion

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D54941

Modified:

clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-implicit-bool-conversion.rst

clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolConversionCheck.cpp?rev=347671&r1=347670&r2=347671&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
Tue Nov 27 08:23:39 2018
@@ -306,6 +306,11 @@ void ImplicitBoolConversionCheck::regist
   auto boolOpAssignment =
   binaryOperator(anyOf(hasOperatorName("|="), hasOperatorName("&=")),
  hasLHS(expr(hasType(booleanType();
+  auto bitfieldAssignment = binaryOperator(
+  hasLHS(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1));
+  auto bitfieldConstruct = cxxConstructorDecl(hasDescendant(cxxCtorInitializer(
+  withInitializer(equalsBoundNode("implicitCastFromBool")),
+  forField(hasBitWidth(1);
   Finder->addMatcher(
   implicitCastExpr(
   implicitCastFromBool,
@@ -313,14 +318,15 @@ void ImplicitBoolConversionCheck::regist
   // in such context:
   //   bool_expr_a == bool_expr_b
   //   bool_expr_a != bool_expr_b
-  unless(hasParent(binaryOperator(
-  anyOf(boolComparison, boolXor, boolOpAssignment,
+  unless(hasParent(binaryOperator(anyOf(
+  boolComparison, boolXor, boolOpAssignment, 
bitfieldAssignment,
+  implicitCastExpr().bind("implicitCastFromBool"),
+  unless(hasParent(bitfieldConstruct)),
   // Check also for nested casts, for example: bool -> int -> float.
   anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
 anything()),
   unless(isInTemplateInstantiation()),
-  unless(hasAncestor(functionTemplateDecl(
-  .bind("implicitCastFromBool"),
+  unless(hasAncestor(functionTemplateDecl(,
   this);
 }
 

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-implicit-bool-conversion.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-implicit-bool-conversion.rst?rev=347671&r1=347670&r2=347671&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-implicit-bool-conversion.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-implicit-bool-conversion.rst
 Tue Nov 27 08:23:39 2018
@@ -74,7 +74,8 @@ In general, the following conversion typ
 
 - pointer/pointer to member/``nullptr``/``NULL`` to boolean,
 
-- boolean expression/literal to integer,
+- boolean expression/literal to integer (conversion from boolean to a single
+  bit bitfield is explicitly allowed),
 
 - boolean expression/literal to floating.
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion.cpp?rev=347671&r1=347670&r2=347671&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion.cpp
 Tue Nov 27 08:23:39 2018
@@ -444,14 +444,27 @@ struct S {
   int a;
   int b : 1;
   int c : 2;
+
+  S(bool a, bool b, bool c) : a(a), b(b), c(c) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion bool -> 
'int'
+  // CHECK-MESSAGES: :[[@LINE-2]]:45: warning: implicit conversion bool -> 
'int'
+  // CHECK-FIXES: S(bool a, bool b, bool c) : a(static_cast(a)), b(b), 
c(static_cast(c)) {}
 };
 
-bool f(const S& s) {
+bool f(S& s) {
   functionTaking(s.a);
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> 
bool
   // CHECK-FIXES: functionTaking(s.a != 0);
   functionTaking(s.b);
   // CHECK-FIXES: functionTaking(s.b);
+  s.a = true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: implicit convers

[clang-tools-extra] r353092 - [clang-tidy] Handle unions with existing default-member-init

2019-02-04 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Mon Feb  4 13:09:31 2019
New Revision: 353092

URL: http://llvm.org/viewvc/llvm-project?rev=353092&view=rev
Log:
[clang-tidy] Handle unions with existing default-member-init

Summary:
clang-tidy's modernize-use-default-member-init was crashing for unions
with an existing default member initializer.

Fixes PR40492

Reviewers: aaron.ballman, alexfh, JonasToth

Reviewed By: JonasToth

Subscribers: JonasToth, riccibruno, xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D57665

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=353092&r1=353091&r2=353092&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Mon Feb  4 13:09:31 2019
@@ -273,7 +273,7 @@ void UseDefaultMemberInitCheck::checkDef
 
 void UseDefaultMemberInitCheck::checkExistingInit(
 const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) {
-  const FieldDecl *Field = Init->getMember();
+  const FieldDecl *Field = Init->getAnyMember();
 
   if (!sameValue(Field->getInClassInitializer(), Init->getInit()))
 return;

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=353092&r1=353091&r2=353092&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
Mon Feb  4 13:09:31 2019
@@ -382,6 +382,16 @@ struct ExistingString {
   const char *e4 = "bar";
 };
 
+struct UnionExisting {
+  UnionExisting() : e(5.0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: member initializer for 'e' is 
redundant
+  // CHECK-FIXES: UnionExisting()  {}
+  union {
+int i;
+double e = 5.0;
+  };
+};
+
 template 
 struct NegativeTemplateExisting {
   NegativeTemplateExisting(int) : t(0) {}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r353554 - [clang-tidy] Don't use assignment for value-initialized enums

2019-02-08 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Fri Feb  8 11:44:42 2019
New Revision: 353554

URL: http://llvm.org/viewvc/llvm-project?rev=353554&view=rev
Log:
[clang-tidy] Don't use assignment for value-initialized enums

Summary:
The modernize-use-default-member-init check crashes when trying to
create an assignment value for a value-initialized enum because it isn't a
BuiltinType.
An enum cannot be initialized by assigning 0 to it unless a cast is added.
It could be initialized with an enumerator with the value 0, but there might not
be one.
Avoid these issues by ignoring the UseAssignment setting for value-initialized
enums.

Fixes PR35050.

Reviewers: aaron.ballman, alexfh, JonasToth

Reviewed By: JonasToth

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57852

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=353554&r1=353553&r2=353554&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Fri Feb  8 11:44:42 2019
@@ -255,17 +255,20 @@ void UseDefaultMemberInitCheck::checkDef
   CharSourceRange InitRange =
   CharSourceRange::getCharRange(LParenEnd, Init->getRParenLoc());
 
+  bool ValueInit = isa(Init->getInit());
+  bool CanAssign = UseAssignment && (!ValueInit || 
!Init->getInit()->getType()->isEnumeralType());
+
   auto Diag =
   diag(Field->getLocation(), "use default member initializer for %0")
   << Field
-  << FixItHint::CreateInsertion(FieldEnd, UseAssignment ? " = " : "{")
+  << FixItHint::CreateInsertion(FieldEnd, CanAssign ? " = " : "{")
   << FixItHint::CreateInsertionFromRange(FieldEnd, InitRange);
 
-  if (UseAssignment && isa(Init->getInit()))
+  if (CanAssign && ValueInit)
 Diag << FixItHint::CreateInsertion(
 FieldEnd, getValueOfValueInit(Init->getInit()->getType()));
 
-  if (!UseAssignment)
+  if (!CanAssign)
 Diag << FixItHint::CreateInsertion(FieldEnd, "}");
 
   Diag << FixItHint::CreateRemoval(Init->getSourceRange());

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp?rev=353554&r1=353553&r2=353554&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp
 Fri Feb  8 11:44:42 2019
@@ -166,6 +166,14 @@ struct PositiveEnum {
   // CHECK-FIXES: Enum e = Foo;
 };
 
+struct PositiveValueEnum {
+  PositiveValueEnum() : e() {}
+  // CHECK-FIXES: PositiveValueEnum()  {}
+  Enum e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer 
for 'e'
+  // CHECK-FIXES: Enum e{};
+};
+
 struct PositiveString {
   PositiveString() : s("foo") {}
   // CHECK-FIXES: PositiveString()  {}

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=353554&r1=353553&r2=353554&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
Fri Feb  8 11:44:42 2019
@@ -165,6 +165,14 @@ struct PositiveEnum {
   // CHECK-FIXES: Enum e{Foo};
 };
 
+struct PositiveValueEnum {
+  PositiveValueEnum() : e() {}
+  // CHECK-FIXES: PositiveValueEnum()  {}
+  Enum e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer 
for 'e'
+  // CHECK-FIXES: Enum e{};
+};
+
 struct PositiveString {
   PositiveString() : s("foo") {}
   // CHECK-FIXES: PositiveString()  {}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r310983 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-09-19 Thread Malcolm Parsons via cfe-commits
On 16 August 2017 at 02:49, Richard Smith via cfe-commits
 wrote:

> +  /// \brief \c true if a defaulted destructor for this class would be 
> deleted.
> +  bool defaultedDestructorIsDeleted() const {
> +return !data().DefaultedDestructorIsDeleted;
> +  }

Is the ! intentional?

-- 
Malcolm Parsons
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329914 - Diagnose cases of "return x" that should be "return std::move(x)" for efficiency

2018-04-12 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Thu Apr 12 07:48:48 2018
New Revision: 329914

URL: http://llvm.org/viewvc/llvm-project?rev=329914&view=rev
Log:
Diagnose cases of "return x" that should be "return std::move(x)" for efficiency

Summary:
This patch adds two new diagnostics, which are off by default:

**-Wreturn-std-move**

This diagnostic is enabled by `-Wreturn-std-move`, `-Wmove`, or `-Wall`.
Diagnose cases of `return x` or `throw x`, where `x` is the name of a local 
variable or parameter, in which a copy operation is performed when a move 
operation would have been available. The user probably expected a move, but 
they're not getting a move, perhaps because the type of "x" is different from 
the return type of the function.
A place where this comes up in the wild is `stdext::inplace_function` 
which implements conversion via a conversion operator rather than a converting 
constructor; see https://github.com/WG21-SG14/SG14/issues/125#issue-297201412
Another place where this has come up in the wild, but where the fix ended up 
being different, was

try { ... } catch (ExceptionType ex) {
throw ex;
}

where the appropriate fix in that case was to replace `throw ex;` with 
`throw;`, and incidentally to catch by reference instead of by value. (But one 
could contrive a scenario where the slicing was intentional, in which case 
throw-by-move would have been the appropriate fix after all.)
Another example (intentional slicing to a base class) is dissected in 
https://github.com/accuBayArea/Slides/blob/master/slides/2018-03-07.pdf

**-Wreturn-std-move-in-c++11**

This diagnostic is enabled only by the exact spelling 
`-Wreturn-std-move-in-c++11`.
Diagnose cases of "return x;" or "throw x;" which in this version of Clang *do* 
produce moves, but which prior to Clang 3.9 / GCC 5.1 produced copies instead. 
This is useful in codebases which care about portability to those older 
compilers.
The name "-in-c++11" is not technically correct; what caused the 
version-to-version change in behavior here was actually CWG 1579, not C++14. I 
think it's likely that codebases that need portability to GCC 4.9-and-earlier 
may understand "C++11" as a colloquialism for "older compilers." The wording of 
this diagnostic is based on feedback from @rsmith.

**Discussion**

Notice that this patch is kind of a negative-space version of Richard Trieu's 
`-Wpessimizing-move`. That diagnostic warns about cases of `return 
std::move(x)` that should be `return x` for speed. These diagnostics warn about 
cases of `return x` that should be `return std::move(x)` for speed. (The two 
diagnostics' bailiwicks do not overlap: we don't have to worry about a `return` 
statement flipping between the two states indefinitely.)

I propose to write a paper for San Diego that would relax the implicit-move 
rules so that in C++2a the user //would// see the moves they expect, and the 
diagnostic could be re-worded in a later version of Clang to suggest explicit 
`std::move` only "in C++17 and earlier." But in the meantime (and/or forever if 
that proposal is not well received), this diagnostic will be useful to detect 
accidental copy operations.

Reviewers: rtrieu, rsmith

Reviewed By: rsmith

Subscribers: lebedev.ri, Rakete, rsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D43322

Patch by Arthur O'Dwyer.

Added:
cfe/trunk/test/SemaCXX/warn-return-std-move.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=329914&r1=329913&r2=329914&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Apr 12 07:48:48 2018
@@ -383,7 +383,11 @@ def DeprecatedObjCIsaUsage : DiagGroup<"
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
 def Packed : DiagGroup<"packed">;
 def Padded : DiagGroup<"padded">;
+
 def PessimizingMove : DiagGroup<"pessimizing-move">;
+def ReturnStdMoveInCXX11 : DiagGroup<"return-std-move-in-c++11">;
+def ReturnStdMove : DiagGroup<"return-std-move">;
+
 def PointerArith : DiagGroup<"pointer-arith">;
 def PoundWarning : DiagGroup<"#warnings">;
 def PoundPragmaMessage : DiagGroup<"#pragma-messages">,
@@ -723,7 +727,12 @@ def IntToVoidPointerCast : DiagGroup<"in
 def IntToPointerCast : DiagGroup<"int-to-pointer-cast",
  [IntToVoidPointerCast]>;
 
-def Move : DiagGroup<"move", [PessimizingMove, RedundantMove, SelfMove]>;
+def Move : DiagGroup<"move", [
+PessimizingMove,
+RedundantMove,
+ReturnStdMove,
+SelfMove
+  ]>;
 
 def Extra : DiagGroup<"extra", [
 MissingFieldIniti

Re: r330068 - [Serialization] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2018-04-14 Thread Malcolm Parsons via cfe-commits
On Sat, 14 Apr 2018, 04:22 Richard Trieu via cfe-commits, <
cfe-commits@lists.llvm.org> wrote:

> I was tracking down a similar issue to the lldb issue before noticing the
> change was reverted.  The bad change that lead to it is:
>
>  // Load pending declaration chains.
> -for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
> -  loadPendingDeclChain(PendingDeclChains[I].first,
> PendingDeclChains[I].second);
> +for (const auto &I : PendingDeclChains)
> +  loadPendingDeclChain(I.first, I.second);
>  PendingDeclChains.clear();
>
> Although the two looks like similar, the vector PendingDeclChains is a
> class member and gets new elements during loop runs.  Once enough elements
> are added to the vector, it get reallocated to a larger memory, but the
> loop is still trying to process the old, now freed, memory.  Using an index
> and checking the size every loop is the right way to process this vector.
>

Should clang-tidy handle this type of loop differently?

-- 
Malcolm Parsons
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r330068 - [Serialization] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2018-04-14 Thread Malcolm Parsons via cfe-commits
On Sat, 14 Apr 2018, 14:16 Kim Gräsman,  wrote:

> That would be a nice outcome of all the "run-tools-on-llvm" changes if any
> problems were filed as bugs on the tools. We have a number of them filed on
> iwyu, and they make for nice, concrete bugs to troubleshoot even if we
> don't always know how to fix them.
>
> For this specific clang-tidy issue, do you have any ideas for how to tell
> this loop apart from any other? I'm guessing the container is modified
> while iterating... Or do you mean skip all non-iterator loops?
>

Non-iterator, mutable container, size checked each iteration.

Clang-tidy could suggest modernisation, but not automatically fix.

-- 
Malcolm Parsons
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r330112 - Clean carriage returns from lib/ and include/. NFC.

2018-04-16 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Mon Apr 16 01:31:08 2018
New Revision: 330112

URL: http://llvm.org/viewvc/llvm-project?rev=330112&view=rev
Log:
Clean carriage returns from lib/ and include/. NFC.

Summary:
Clean carriage returns from lib/ and include/. NFC.
(I have to make this change locally in order for `git diff` to show sane output 
after I edit a file, so I might as well ask for it to be committed. I don't 
have commit privs myself.)
(Without this patch, `git rebase`ing any change involving SemaDeclCXX.cpp is a 
real nightmare. :( So while I have no right to ask for this to be committed, 
geez would it make my workflow easier if it were.)

Here's the command I used to reformat things. (Requires bash and OSX/FreeBSD 
sed.)

git grep -l $'\r' lib include | xargs sed -i -e $'s/\r//'
find lib include -name '*-e' -delete

Reviewers: malcolm.parsons

Reviewed By: malcolm.parsons

Subscribers: emaste, krytarowski, cfe-commits

Differential Revision: https://reviews.llvm.org/D45591

Patch by Arthur O'Dwyer.

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=330112&r1=330111&r2=330112&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Apr 16 01:31:08 2018
@@ -2213,14 +2213,14 @@ void ASTDumper::VisitArrayInitIndexExpr(
 }
 
 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
-  VisitExpr(Node);
-  OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
- << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
-  if (!Node->canOverflow())
-OS << " cannot overflow";
-}
-
-void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
+  VisitExpr(Node);
+  OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
+ << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
+  if (!Node->canOverflow())
+OS << " cannot overflow";
+}
+
+void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
 const UnaryExprOrTypeTraitExpr *Node) {
   VisitExpr(Node);
   switch(Node->getKind()) {

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=330112&r1=330111&r2=330112&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Apr 16 01:31:08 2018
@@ -3328,12 +3328,12 @@ static bool handleAssignment(EvalInfo &I
   }
 
   CompleteObject Obj = findCompleteObject(Info, E, AK_Assign, LVal, LValType);
-  return Obj && modifySubobject(Info, E, Obj, LVal.Designator, Val);
-}
-
-namespace {
-struct CompoundAssignSubobjectHandler {
-  EvalInfo &Info;
+  return Obj && modifySubobject(Info, E, Obj, LVal.Designator, Val);
+}
+
+namespace {
+struct CompoundAssignSubobjectHandler {
+  EvalInfo &Info;
   const Expr *E;
   QualType PromotedLHSType;
   BinaryOperatorKind Opcode;
@@ -3449,13 +3449,13 @@ static bool handleCompoundAssignment(
   return Obj && findSubobject(Info, E, Obj, LVal.Designator, Handler);
 }
 
-namespace {
-struct IncDecSubobjectHandler {
-  EvalInfo &Info;
-  const UnaryOperator *E;
-  AccessKinds AccessKind;
-  APValue *Old;
-
+namespace {
+struct IncDecSubobjectHandler {
+  EvalInfo &Info;
+  const UnaryOperator *E;
+  AccessKinds AccessKind;
+  APValue *Old;
+
   typedef bool result_type;
 
   bool checkConst(QualType QT) {
@@ -3521,20 +3521,20 @@ struct IncDecSubobjectHandler {
 }
 
 bool WasNegative = Value.isNegative();
-if (AccessKind == AK_Increment) {
-  ++Value;
-
-  if (!WasNegative && Value.isNegative() && E->canOverflow()) {
-APSInt ActualValue(Value, /*IsUnsigned*/true);
-return HandleOverflow(Info, E, ActualValue, SubobjType);
-  }
-} else {
-  --Value;
-
-  if (WasNegative && !Value.isNegative() && E->canOverflow()) {
-unsigned BitWidth = Value.getBitWidth();
-APSInt ActualValue(Value.sext(BitWidth + 1), /*IsUnsigned*/false);
-ActualValue.setBit(BitWidth);
+if (AccessKind == AK_Increment) {
+  ++Value;
+
+  if (!WasNegative && Value.isNegative() && E->canOverflow()) {
+APSInt ActualValue(Value, /*IsUnsigned*/true);
+return HandleOverflow(Info, E, ActualValue, SubobjType);
+  }
+} else {
+  --Value;
+
+  if (WasNegative && !Value.isNegative() && E->canOverflow()) {
+unsigned BitWidth = Value.getBitWidth();
+APSInt ActualValue(Value.sext(BitWidth + 1), /*IsUnsigned*/false);
+ActualValue.setBit(B

r331361 - [analyzer] Fix filename in cross-file HTML report

2018-05-02 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed May  2 07:26:12 2018
New Revision: 331361

URL: http://llvm.org/viewvc/llvm-project?rev=331361&view=rev
Log:
[analyzer] Fix filename in cross-file HTML report

Summary:
The filename is currently taken from the start of the path, while the
line and column are taken from the end of the path.
This didn't matter until cross-file path reporting was added.

Reviewers: george.karpenkov, dcoughlin, vlad.tsyrklevich

Reviewed By: george.karpenkov, vlad.tsyrklevich

Subscribers: xazax.hun, szepet, a.sidorin, cfe-commits

Differential Revision: https://reviews.llvm.org/D45611

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
cfe/trunk/test/Coverage/html-multifile-diagnostics.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=331361&r1=331360&r2=331361&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Wed May  2 07:26:12 
2018
@@ -321,7 +321,9 @@ std::string HTMLDiagnostics::GenerateHTM
 return {};
 
   // Add CSS, header, and footer.
-  const FileEntry* Entry = SMgr.getFileEntryForID(FileIDs[0]);
+  FileID FID =
+  path.back()->getLocation().asLocation().getExpansionLoc().getFileID();
+  const FileEntry* Entry = SMgr.getFileEntryForID(FID);
   FinalizeHTML(D, R, SMgr, path, FileIDs[0], Entry, declName);
 
   std::string file;

Modified: cfe/trunk/test/Coverage/html-multifile-diagnostics.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/html-multifile-diagnostics.c?rev=331361&r1=331360&r2=331361&view=diff
==
--- cfe/trunk/test/Coverage/html-multifile-diagnostics.c (original)
+++ cfe/trunk/test/Coverage/html-multifile-diagnostics.c Wed May  2 07:26:12 
2018
@@ -4,6 +4,8 @@
 
 // REQUIRES: staticanalyzer
 
+// CHECK: 
+
 // CHECK: Annotated Source Code
 
 // Make sure it's generated as multi-file HTML output


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r337152 - [Sema] Reword warning for constant captures that are not required

2018-07-17 Thread Malcolm Parsons via cfe-commits
On Mon, 16 Jul 2018 at 10:57, Benjamin Kramer via cfe-commits
 wrote:
> -  auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // 
> expected-warning{{lambda capture 'i' is not required to be captured for this 
> use}}
> +  auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // 
> expected-warning{{lambda capture of constant 'i' is not required for this 
> use}}

i is not a constant:

  int i = 0;

-- 
Malcolm Parsons
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-09-19 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 71802.
malcolm.parsons added a comment.

Handle delegating and base class constructors


https://reviews.llvm.org/D24339

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tidy/readability/RedundantMemberInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-member-init.rst
  test/clang-tidy/readability-redundant-member-init.cpp

Index: test/clang-tidy/readability-redundant-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-member-init.cpp
@@ -0,0 +1,134 @@
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+
+struct S {
+  S() = default;
+  S(int i) : i(i) {}
+  int i = 1;
+};
+
+struct T {
+  T(int i = 1) : i(i) {}
+  int i;
+};
+
+struct U {
+  int i;
+};
+
+// Initializer calls default constructor
+struct F1 {
+  F1() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F1()  {}
+  S f;
+};
+
+// Initializer calls default constructor with default argument
+struct F2 {
+  F2() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F2()  {}
+  T f;
+};
+
+// Multiple redundant initializers for same constructor
+struct F3 {
+  F3() : f(), g(1), h() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for 'f' is redundant [readability-redundant-member-init]
+  // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: initializer for 'h' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F3() : g(1) {}
+  S f, g, h;
+};
+
+// Templated class independent type
+template 
+struct F4 {
+  F4() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F4()  {}
+  S f;
+};
+F4 f4i;
+F4 f4s;
+
+// Base class
+struct F5 : S {
+  F5() : S() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for 'S' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F5()  {}
+};
+
+// Initializer not written
+struct NF1 {
+  NF1() {}
+  S f;
+};
+
+// Initializer doesn't call default constructor
+struct NF2 {
+  NF2() : f(1) {}
+  S f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF3 {
+  NF3() : f(1) {}
+  T f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF4 {
+  NF4() : f(2) {}
+  T f;
+};
+
+// Initializer is zero-initialization
+struct NF5 {
+  NF5() : i() {}
+  int i;
+};
+
+// Initializer is direct-initialization
+struct NF6 {
+  NF6() : i(1) {}
+  int i;
+};
+
+// Initializer is aggregate initialization of struct
+struct NF7 {
+  NF7() : f{} {}
+  U f;
+};
+
+// Initializer is aggregate initialization of array
+struct NF8 {
+  NF8() : f{} {}
+  int f[2];
+};
+
+struct NF9 {
+  NF9() : f{} {}
+  S f[2];
+};
+
+// Initializing member of union
+union NF10 {
+  NF10() : s() {}
+  int i;
+  S s;
+};
+
+// Templated class dependent type
+template 
+struct NF11 {
+  NF11() : f() {}
+  V f;
+};
+NF11 nf11i;
+NF11 nf11s;
+
+// Delegating constructor
+class NF12 {
+  NF12() = default;
+  NF12(int) : NF12() {}
+};
Index: docs/clang-tidy/checks/readability-redundant-member-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-member-init.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - readability-redundant-member-init
+
+readability-redundant-member-init
+=
+
+Finds member initializations that are unnecessary because the same default
+constructor would be called if they were not present.
+
+Example:
+
+.. code-block:: c++
+
+  // Explicitly initializing the member s is unnecessary.  
+  class Foo {
+  public:
+Foo() : s() {}
+
+  private:
+std::string s;
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -133,6 +133,7 @@
readability-named-parameter
readability-non-const-parameter
readability-redundant-control-flow
+   readability-redundant-member-init
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -111,6 +111,12 @@
   Flags function parameters of a pointer type that could be 

Re: [PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-09-22 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 72181.
malcolm.parsons added a comment.

Don't remove init of const members.
Do remove calls to constructors that introduce cleanups.


https://reviews.llvm.org/D24339

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tidy/readability/RedundantMemberInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-member-init.rst
  test/clang-tidy/readability-redundant-member-init.cpp

Index: test/clang-tidy/readability-redundant-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-member-init.cpp
@@ -0,0 +1,156 @@
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+
+struct S {
+  S() = default;
+  S(int i) : i(i) {}
+  int i = 1;
+};
+
+struct T {
+  T(int i = 1) : i(i) {}
+  int i;
+};
+
+struct U {
+  int i;
+};
+
+// Initializer calls default constructor
+struct F1 {
+  F1() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F1()  {}
+  S f;
+};
+
+// Initializer calls default constructor with default argument
+struct F2 {
+  F2() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F2()  {}
+  T f;
+};
+
+// Multiple redundant initializers for same constructor
+struct F3 {
+  F3() : f(), g(1), h() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: initializer for member 'h' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F3() : g(1) {}
+  S f, g, h;
+};
+
+// Templated class independent type
+template 
+struct F4 {
+  F4() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F4()  {}
+  S f;
+};
+F4 f4i;
+F4 f4s;
+
+// Base class
+struct F5 : S {
+  F5() : S() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F5()  {}
+};
+
+// Constructor call requires cleanup
+struct Cleanup {
+  ~Cleanup() {}
+};
+
+struct UsesCleanup {
+  UsesCleanup(const Cleanup &c = Cleanup()) {}
+};
+
+struct F6 {
+  F6() : uc() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'uc' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES:  F6()  {}
+  UsesCleanup uc;
+};
+
+// Initializer not written
+struct NF1 {
+  NF1() {}
+  S f;
+};
+
+// Initializer doesn't call default constructor
+struct NF2 {
+  NF2() : f(1) {}
+  S f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF3 {
+  NF3() : f(1) {}
+  T f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF4 {
+  NF4() : f(2) {}
+  T f;
+};
+
+// Initializer is zero-initialization
+struct NF5 {
+  NF5() : i() {}
+  int i;
+};
+
+// Initializer is direct-initialization
+struct NF6 {
+  NF6() : i(1) {}
+  int i;
+};
+
+// Initializer is aggregate initialization of struct
+struct NF7 {
+  NF7() : f{} {}
+  U f;
+};
+
+// Initializer is aggregate initialization of array
+struct NF8 {
+  NF8() : f{} {}
+  int f[2];
+};
+
+struct NF9 {
+  NF9() : f{} {}
+  S f[2];
+};
+
+// Initializing member of union
+union NF10 {
+  NF10() : s() {}
+  int i;
+  S s;
+};
+
+// Templated class dependent type
+template 
+struct NF11 {
+  NF11() : f() {}
+  V f;
+};
+NF11 nf11i;
+NF11 nf11s;
+
+// Delegating constructor
+class NF12 {
+  NF12() = default;
+  NF12(int) : NF12() {}
+};
+
+// Const member
+struct NF13 {
+  NF13() : f() {}
+  const S f;
+};
Index: docs/clang-tidy/checks/readability-redundant-member-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-member-init.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - readability-redundant-member-init
+
+readability-redundant-member-init
+=
+
+Finds member initializations that are unnecessary because the same default
+constructor would be called if they were not present.
+
+Example:
+
+.. code-block:: c++
+
+  // Explicitly initializing the member s is unnecessary.  
+  class Foo {
+  public:
+Foo() : s() {}
+
+  private:
+std::string s;
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tid

Re: [PATCH] D24848: [clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init with in-class initializers

2016-09-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.


Comment at: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp:372
@@ +371,3 @@
+
+struct Bug30487
+{

There's already this test:

```
struct NegativeInClassInitialized {
int F = 0;  
NegativeInClassInitialized() {}
};
```

I'd call your test NegativeInClassInitializedImplicit, and also add this:

```
struct NegativeInClassInitializedDefaulted {
int F = 0;
NegativeInClassInitializedDefaulted() = default;
};
```


https://reviews.llvm.org/D24848



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24652: [clang-tidy] readability-avoid-const-params-in-decls template instantiation bugfix

2016-09-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 72476.
malcolm.parsons added a comment.

Expand code comment


https://reviews.llvm.org/D24652

Files:
  clang-tidy/readability/AvoidConstParamsInDecls.cpp
  test/clang-tidy/readability-avoid-const-params-in-decls.cpp

Index: test/clang-tidy/readability-avoid-const-params-in-decls.cpp
===
--- test/clang-tidy/readability-avoid-const-params-in-decls.cpp
+++ test/clang-tidy/readability-avoid-const-params-in-decls.cpp
@@ -53,6 +53,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
 // CHECK-FIXES: void F12(bool b = true);
 
+template
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13();
+
 struct Foo {
   Foo(const int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
@@ -63,6 +69,18 @@
   // CHECK-FIXES: void operator()(int i);
 };
 
+template 
+struct FooT {
+  FooT(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+  // CHECK-FIXES: FooT(int i);
+
+  void operator()(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(int i);
+};
+FooT f(1);
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -72,6 +90,25 @@
 void NF6(const int *const) {}
 void NF7(int, const int) {}
 void NF8(const int, const int) {}
+template 
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+  Bar(const int i) {}
+
+  void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template 
+struct BarT {
+  BarT(const int i) {}
+
+  void operator()(const int i) {}
+};
+BarT b(1);
 
 // Do not match on other stuff
 void NF(const alias_type& i);
Index: clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -36,7 +36,12 @@
   functionDecl(unless(isDefinition()),
// Lambdas are always their own definition, but they
// generate a non-definition FunctionDecl too. Ignore those.
-   unless(cxxMethodDecl(ofClass(cxxRecordDecl(isLambda(),
+   // Class template instantiations have a non-definition
+   // CXXMethodDecl for methods that aren't used in this
+   // translation unit. Ignore those, as the template will have
+   // already been checked.
+   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(
+   isLambda(), 
ast_matchers::isTemplateInstantiation()),
has(typeLoc(forEach(ConstParamDecl
   .bind("func"),
   this);


Index: test/clang-tidy/readability-avoid-const-params-in-decls.cpp
===
--- test/clang-tidy/readability-avoid-const-params-in-decls.cpp
+++ test/clang-tidy/readability-avoid-const-params-in-decls.cpp
@@ -53,6 +53,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
 // CHECK-FIXES: void F12(bool b = true);
 
+template
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13();
+
 struct Foo {
   Foo(const int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
@@ -63,6 +69,18 @@
   // CHECK-FIXES: void operator()(int i);
 };
 
+template 
+struct FooT {
+  FooT(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+  // CHECK-FIXES: FooT(int i);
+
+  void operator()(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(int i);
+};
+FooT f(1);
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -72,6 +90,25 @@
 void NF6(const int *const) {}
 void NF7(int, const int) {}
 void NF8(const int, const int) {}
+template 
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+  Bar(const int i) {}
+
+  void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template 
+struct BarT {
+  BarT(const int i) {}
+
+  void operator()(const int i) {}
+};
+BarT b(1);
 
 // Do not match on other stuff
 void NF(const alias_type& i);
Index: clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -36,7 +36,12 @@
   functionDecl(unless(isDefinition()),
// Lambdas are always their own definition, but th

Re: [PATCH] D24652: [clang-tidy] readability-avoid-const-params-in-decls template instantiation bugfix

2016-09-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.


Comment at: clang-tidy/readability/AvoidConstParamsInDecls.cpp:39
@@ -38,2 +38,3 @@
// generate a non-definition FunctionDecl too. Ignore those.
-   unless(cxxMethodDecl(ofClass(cxxRecordDecl(isLambda(),
+   // Ignore template instantiations too.
+   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(

alexfh wrote:
> Would be helpful to expand on why we're ignoring only member function of 
> class instantiations (and not instantiations of member or free standing 
> functions, for example).
AFAICT, template instantiations of member and free standing functions are 
definitions when the template is a definition.


https://reviews.llvm.org/D24652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24444: [clang-tidy] modernize-use-default default constructor bugfix

2016-09-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

ping


https://reviews.llvm.org/D2



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24444: [clang-tidy] modernize-use-default default constructor bugfix

2016-09-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

I don't have commit access, so please commit this and 
https://reviews.llvm.org/D24652 for me.
Thanks.


https://reviews.llvm.org/D2



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24887: [clang-tidy] cert-err58-cpp should not apply to function scope objects

2016-09-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

I don't have commit access, so please commit it for me.
Thanks.


https://reviews.llvm.org/D24887



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24965: [clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives

2016-09-27 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: alexfh, aaron.ballman, omtcyfz.
malcolm.parsons added subscribers: cfe-commits, mgehre.
Herald added a subscriber: nemanjai.

Handle classes with default constructors that are defaulted or are not
present in the AST.
Classes with virtual methods or virtual bases are not trivially
default constructible, so their members and bases need to be initialized.

https://reviews.llvm.org/D24965

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  clang-tidy/utils/TypeTraits.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -367,3 +367,25 @@
   PositiveIndirectMember() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
 };
+
+struct PositiveVirtualMethod {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual int f() = 0;
+};
+
+struct PositiveVirtualDestructor {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  PositiveVirtualDestructor() = default;
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual ~PositiveVirtualDestructor() {}
+};
+
+struct PositiveVirtualBase : public virtual NegativeAggregateType {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these bases: NegativeAggregateType
+  // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+};
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -58,6 +58,9 @@
   // constructible.
   if (ClassDecl->hasUserProvidedDefaultConstructor())
 return false;
+  // A polymorphic class is not trivially constructible
+  if (ClassDecl->isPolymorphic())
+return false;
   // A class is trivially constructible if it has a trivial default constructor.
   if (ClassDecl->hasTrivialDefaultConstructor())
 return true;
@@ -71,6 +74,8 @@
   for (const CXXBaseSpecifier &Base : ClassDecl->bases()) {
 if (!isTriviallyDefaultConstructible(Base.getType(), Context))
   return false;
+if (Base.isVirtual())
+  return false;
   }
 
   return true;
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -46,11 +46,13 @@
   // To fix: Write a data member initializer, or mention it in the member
   // initializer list.
   void checkMissingMemberInitializer(ASTContext &Context,
+ const CXXRecordDecl *ClassDecl,
  const CXXConstructorDecl *Ctor);
 
   // A subtle side effect of Type.6 part 2:
   // Make sure to initialize trivially constructible base classes.
   void checkMissingBaseClassInitializer(const ASTContext &Context,
+const CXXRecordDecl *ClassDecl,
 const CXXConstructorDecl *Ctor);
 
   // Checks Type.6 part 2:
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -269,6 +269,19 @@
IsNonTrivialDefaultConstructor))
   .bind("ctor"),
   this);
+
+  // Match classes with a default constructor that is defaulted or is not in the
+  // AST.
+  Finder->addMatcher(
+  cxxRecordDecl(
+  isDefinition(),
+  anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(),
+   unless(isImplicit(,
+unless(has(cxxConstructorDecl(,
+  unless(isTriviallyDefaultConstructible()))
+  .bind("record"),
+  this);
+
   auto HasDefaultConstructor = hasInitializer(
   cxxConstructExpr(unless(requiresZeroInitialization()),
hasDeclaration(cxxConstructorDecl(
@@ -287,8 +300,13 @@
 // Skip declarations delayed by late template parsing without a body.
 if (!Ctor->getBody())
   return;
-checkMissingMemberInitializer(*Result.Context, Ctor);
-checkMissingBaseClassInitializer(*Result.Context, Ctor);
+checkMissingMemberInitializer(*Result.Context, Ctor->getParent(), Ctor);
+checkMissingBaseClassInitializer(*Result.Context, Ctor->getParent(),

Re: [PATCH] D24886: Add [[clang::suppress(rule, ...)]] attribute

2016-09-27 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a subscriber: malcolm.parsons.
malcolm.parsons added a comment.

In https://reviews.llvm.org/D24886#554130, @mgehre wrote:

> 2. Also, I suspect we will want this attribute to also be written on types I 
> was thinking about a case were that was useful, and didn't find any. Which of 
> course doesn't mean that there is none. I will add this.


I would like to suppress cppcoreguidelines-pro-type-union-access for all member 
functions of a class.
It might be useful to suppress cppcoreguidelines-pro-type-member-init for all 
constructors of a class.


https://reviews.llvm.org/D24886



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24848: [clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init with in-class initializers

2016-09-27 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D24848#554145, @mgehre wrote:

> Rename the struct that was introduced in the test. Note that I need to keep 
> the function Bug30487,
>  because that is where the false-positive warning was emitted.


https://reviews.llvm.org/D24965 will allow you to write a positive test instead:

  struct PositivePartiallyInClassInitialized {
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize 
these fields: G
int F = 0;
int G;
// CHECK-FIXES: int G{};
  };


https://reviews.llvm.org/D24848



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22725: [clang-tidy] Add check 'modernize-use-algorithm'

2016-09-28 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a subscriber: malcolm.parsons.
malcolm.parsons added a comment.

This check looks like it implements some of CppCoreGuidelines Bounds.4

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#bounds4-dont-use-standard-library-functions-and-types-that-are-not-bounds-checked


Repository:
  rL LLVM

https://reviews.llvm.org/D22725



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22910: Add support for CXXOperatorCallExpr in Expr::HasSideEffects

2016-09-28 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a subscriber: malcolm.parsons.


Comment at: lib/AST/Expr.cpp:2868
@@ +2867,3 @@
+// When looking for potential side-effects, we assume that these
+// operators: assignment, increement and decrement are intended
+// to have a side-effect and other overloaded operators are not.

typo: increment


https://reviews.llvm.org/D22910



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24848: [clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init with in-class initializers

2016-09-28 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D24848#555636, @mgehre wrote:

> Are you okay with me committing this as it currently is?


Yes.


https://reviews.llvm.org/D24848



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D25024: [clang-tidy] Add check for detecting declarations with multiple names

2016-09-28 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a subscriber: malcolm.parsons.


Comment at: clang-tidy/cppcoreguidelines/OneNamePerDeclarationCheck.cpp:30
@@ +29,3 @@
+  Finder->addMatcher(
+  declStmt(declCountIsGreaterThan(1)).bind("multipleNameDeclaration"),
+  this);

Can declCountIsGreaterThan(1) be written as unless(declCountIs(1))?


https://reviews.llvm.org/D25024



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Updated, 96 lines] D24965: [clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives

2016-09-30 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73019.
malcolm.parsons added a comment.

Rebase


https://reviews.llvm.org/D24965

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  clang-tidy/utils/TypeTraits.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -377,3 +377,25 @@
 {
   NegativeInClassInitializedDefaulted s;
 }
+
+struct PositiveVirtualMethod {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual int f() = 0;
+};
+
+struct PositiveVirtualDestructor {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  PositiveVirtualDestructor() = default;
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual ~PositiveVirtualDestructor() {}
+};
+
+struct PositiveVirtualBase : public virtual NegativeAggregateType {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these bases: NegativeAggregateType
+  // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+};
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -58,6 +58,9 @@
   // constructible.
   if (ClassDecl->hasUserProvidedDefaultConstructor())
 return false;
+  // A polymorphic class is not trivially constructible
+  if (ClassDecl->isPolymorphic())
+return false;
   // A class is trivially constructible if it has a trivial default constructor.
   if (ClassDecl->hasTrivialDefaultConstructor())
 return true;
@@ -73,6 +76,8 @@
   for (const CXXBaseSpecifier &Base : ClassDecl->bases()) {
 if (!isTriviallyDefaultConstructible(Base.getType(), Context))
   return false;
+if (Base.isVirtual())
+  return false;
   }
 
   return true;
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -46,11 +46,13 @@
   // To fix: Write a data member initializer, or mention it in the member
   // initializer list.
   void checkMissingMemberInitializer(ASTContext &Context,
+ const CXXRecordDecl *ClassDecl,
  const CXXConstructorDecl *Ctor);
 
   // A subtle side effect of Type.6 part 2:
   // Make sure to initialize trivially constructible base classes.
   void checkMissingBaseClassInitializer(const ASTContext &Context,
+const CXXRecordDecl *ClassDecl,
 const CXXConstructorDecl *Ctor);
 
   // Checks Type.6 part 2:
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -269,6 +269,19 @@
IsNonTrivialDefaultConstructor))
   .bind("ctor"),
   this);
+
+  // Match classes with a default constructor that is defaulted or is not in the
+  // AST.
+  Finder->addMatcher(
+  cxxRecordDecl(
+  isDefinition(),
+  anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(),
+   unless(isImplicit(,
+unless(has(cxxConstructorDecl(,
+  unless(isTriviallyDefaultConstructible()))
+  .bind("record"),
+  this);
+
   auto HasDefaultConstructor = hasInitializer(
   cxxConstructExpr(unless(requiresZeroInitialization()),
hasDeclaration(cxxConstructorDecl(
@@ -287,8 +300,13 @@
 // Skip declarations delayed by late template parsing without a body.
 if (!Ctor->getBody())
   return;
-checkMissingMemberInitializer(*Result.Context, Ctor);
-checkMissingBaseClassInitializer(*Result.Context, Ctor);
+checkMissingMemberInitializer(*Result.Context, Ctor->getParent(), Ctor);
+checkMissingBaseClassInitializer(*Result.Context, Ctor->getParent(), Ctor);
+  } else if (const auto *Record =
+ Result.Nodes.getNodeAs("record")) {
+assert(Record->hasDefaultConstructor());
+checkMissingMemberInitializer(*Result.Context, Record, nullptr);
+checkMissingBaseClassInitializer(*Result.Context, Record, nullptr);
   } else if (const auto *Var = Result.Nodes.getNodeAs("var")) {
 checkUninitializedTrivialType(*Result.Context, Var);
   }

[PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-10-03 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73260.
malcolm.parsons added a comment.
Herald added a subscriber: modocache.

Don't warn for trivially default constructable members


https://reviews.llvm.org/D24339

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tidy/readability/RedundantMemberInitCheck.h
  clang-tidy/utils/TypeTraits.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-member-init.rst
  test/clang-tidy/readability-redundant-member-init.cpp

Index: test/clang-tidy/readability-redundant-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-member-init.cpp
@@ -0,0 +1,162 @@
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+
+struct S {
+  S() = default;
+  S(int i) : i(i) {}
+  int i = 1;
+};
+
+struct T {
+  T(int i = 1) : i(i) {}
+  int i;
+};
+
+struct U {
+  int i;
+};
+
+// Initializer calls default constructor
+struct F1 {
+  F1() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES: F1() {}
+  S f;
+};
+
+// Initializer calls default constructor with default argument
+struct F2 {
+  F2() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES: F2() {}
+  T f;
+};
+
+// Multiple redundant initializers for same constructor
+struct F3 {
+  F3() : f(), g(1), h() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: initializer for member 'h' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES: F3() : g(1) {}
+  S f, g, h;
+};
+
+// Templated class independent type
+template 
+struct F4 {
+  F4() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES: F4() {}
+  S f;
+};
+F4 f4i;
+F4 f4s;
+
+// Base class
+struct F5 : S {
+  F5() : S() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES: F5() {}
+};
+
+// Constructor call requires cleanup
+struct Cleanup {
+  ~Cleanup() {}
+};
+
+struct UsesCleanup {
+  UsesCleanup(const Cleanup &c = Cleanup()) {}
+};
+
+struct F6 {
+  F6() : uc() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'uc' is redundant [readability-redundant-member-init]
+  // CHECK-FIXES: F6() {}
+  UsesCleanup uc;
+};
+
+// Initializer not written
+struct NF1 {
+  NF1() {}
+  S f;
+};
+
+// Initializer doesn't call default constructor
+struct NF2 {
+  NF2() : f(1) {}
+  S f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF3 {
+  NF3() : f(1) {}
+  T f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF4 {
+  NF4() : f(2) {}
+  T f;
+};
+
+// Initializer is zero-initialization
+struct NF5 {
+  NF5() : i() {}
+  int i;
+};
+
+// Initializer is direct-initialization
+struct NF6 {
+  NF6() : i(1) {}
+  int i;
+};
+
+// Initializer is aggregate initialization of struct
+struct NF7 {
+  NF7() : f{} {}
+  U f;
+};
+
+// Initializer is zero-initialization of struct
+struct NF7b {
+  NF7b() : f() {}
+  U f;
+};
+
+// Initializer is aggregate initialization of array
+struct NF8 {
+  NF8() : f{} {}
+  int f[2];
+};
+
+struct NF9 {
+  NF9() : f{} {}
+  S f[2];
+};
+
+// Initializing member of union
+union NF10 {
+  NF10() : s() {}
+  int i;
+  S s;
+};
+
+// Templated class dependent type
+template 
+struct NF11 {
+  NF11() : f() {}
+  V f;
+};
+NF11 nf11i;
+NF11 nf11s;
+
+// Delegating constructor
+class NF12 {
+  NF12() = default;
+  NF12(int) : NF12() {}
+};
+
+// Const member
+struct NF13 {
+  NF13() : f() {}
+  const S f;
+};
Index: docs/clang-tidy/checks/readability-redundant-member-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-member-init.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - readability-redundant-member-init
+
+readability-redundant-member-init
+=
+
+Finds member initializations that are unnecessary because the same default
+constructor would be called if they were not present.
+
+Example:
+
+.. code-block:: c++
+
+  // Explicitly initializing the member s is unnecessary.
+  class Foo {
+  public:
+Foo() : s() {}
+
+  private:
+std::string s;
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -133,6 +133,7 @@
readability-

[PATCH] D25024: [clang-tidy] Add check for detecting declarations with multiple names

2016-10-03 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.


> cppcoreguidelines-one-name-per-declaration.cpp:8
> +  {
> +int x = 42, y = 43;
> +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Do not declare multiple 
> names per declaration [cppcoreguidelines-one-name-per-declaration]

The guideline says "Flag non-function arguments with multiple declarators 
involving declarator operators (e.g., int* p, q;)".

There are no declarator operators in this test, so there should be no warning.

> aaron.ballman wrote in cppcoreguidelines-one-name-per-declaration.cpp:16
> Please add tests that show the exceptions in the C++ Core Guidelines are 
> properly handled. Also, I'd like to see tests with other named declarations, 
> such as typedefs, template parameter lists, for loop initializers, etc.

and structured bindings (no warning).

https://reviews.llvm.org/D25024



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24965: [clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives

2016-10-04 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73452.
malcolm.parsons added a comment.

Don't match template instantiations.
Add assert message.
Update macro comment.
Add tests for templates and macros.


https://reviews.llvm.org/D24965

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  clang-tidy/utils/TypeTraits.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -377,3 +377,46 @@
 {
   NegativeInClassInitializedDefaulted s;
 }
+
+struct PositiveVirtualMethod {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual int f() = 0;
+};
+
+struct PositiveVirtualDestructor {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  PositiveVirtualDestructor() = default;
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual ~PositiveVirtualDestructor() {}
+};
+
+struct PositiveVirtualBase : public virtual NegativeAggregateType {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these bases: NegativeAggregateType
+  // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+template 
+struct NegativeTemplateVirtualDestructor {
+  T Val;
+  virtual ~NegativeTemplateVirtualDestructor() = default;
+};
+
+template struct NegativeTemplateVirtualDestructor;
+
+#define UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(FIELD) \
+  struct UninitializedFieldVirtual##FIELD {  \
+int FIELD;   \
+virtual ~UninitializedFieldVirtual##FIELD() {}   \
+  }; \
+// Ensure FIELD is not initialized since fixes inside of macros are disabled.
+// CHECK-FIXES: int FIELD;
+
+UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(F);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
+UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -58,6 +58,9 @@
   // constructible.
   if (ClassDecl->hasUserProvidedDefaultConstructor())
 return false;
+  // A polymorphic class is not trivially constructible
+  if (ClassDecl->isPolymorphic())
+return false;
   // A class is trivially constructible if it has a trivial default constructor.
   if (ClassDecl->hasTrivialDefaultConstructor())
 return true;
@@ -73,6 +76,8 @@
   for (const CXXBaseSpecifier &Base : ClassDecl->bases()) {
 if (!isTriviallyDefaultConstructible(Base.getType(), Context))
   return false;
+if (Base.isVirtual())
+  return false;
   }
 
   return true;
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -46,11 +46,13 @@
   // To fix: Write a data member initializer, or mention it in the member
   // initializer list.
   void checkMissingMemberInitializer(ASTContext &Context,
+ const CXXRecordDecl *ClassDecl,
  const CXXConstructorDecl *Ctor);
 
   // A subtle side effect of Type.6 part 2:
   // Make sure to initialize trivially constructible base classes.
   void checkMissingBaseClassInitializer(const ASTContext &Context,
+const CXXRecordDecl *ClassDecl,
 const CXXConstructorDecl *Ctor);
 
   // Checks Type.6 part 2:
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -269,6 +269,19 @@
IsNonTrivialDefaultConstructor))
   .bind("ctor"),
   this);
+
+  // Match classes with a default constructor that is defaulted or is not in the
+  // AST.
+  Finder->addMatcher(
+  cxxRecordDecl(
+  isDefinition(), unless(isInstantiated()),
+  anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(),
+   unless(isImplicit(,
+unless(has(cxxConstructorDecl(,
+  unless(isTriviallyDefaultConstructible()))
+  .bind("record"),

[PATCH] D24965: [clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives

2016-10-04 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73474.
malcolm.parsons added a comment.

Pass records by reference.
Change test to trigger diagnostic for non-template type


https://reviews.llvm.org/D24965

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  clang-tidy/utils/TypeTraits.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -377,3 +377,49 @@
 {
   NegativeInClassInitializedDefaulted s;
 }
+
+struct PositiveVirtualMethod {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual int f() = 0;
+};
+
+struct PositiveVirtualDestructor {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  PositiveVirtualDestructor() = default;
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual ~PositiveVirtualDestructor() {}
+};
+
+struct PositiveVirtualBase : public virtual NegativeAggregateType {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these bases: NegativeAggregateType
+  // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: constructor does not initialize these fields: F
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+template 
+struct PositiveTemplateVirtualDestructor {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
+  T Val;
+  int F;
+  // CHECK-FIXES: int F{};
+  virtual ~PositiveTemplateVirtualDestructor() = default;
+};
+
+template struct PositiveTemplateVirtualDestructor;
+
+#define UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(FIELD) \
+  struct UninitializedFieldVirtual##FIELD {  \
+int FIELD;   \
+virtual ~UninitializedFieldVirtual##FIELD() {}   \
+  }; \
+// Ensure FIELD is not initialized since fixes inside of macros are disabled.
+// CHECK-FIXES: int FIELD;
+
+UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(F);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
+UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -58,6 +58,9 @@
   // constructible.
   if (ClassDecl->hasUserProvidedDefaultConstructor())
 return false;
+  // A polymorphic class is not trivially constructible
+  if (ClassDecl->isPolymorphic())
+return false;
   // A class is trivially constructible if it has a trivial default constructor.
   if (ClassDecl->hasTrivialDefaultConstructor())
 return true;
@@ -73,6 +76,8 @@
   for (const CXXBaseSpecifier &Base : ClassDecl->bases()) {
 if (!isTriviallyDefaultConstructible(Base.getType(), Context))
   return false;
+if (Base.isVirtual())
+  return false;
   }
 
   return true;
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -46,11 +46,13 @@
   // To fix: Write a data member initializer, or mention it in the member
   // initializer list.
   void checkMissingMemberInitializer(ASTContext &Context,
+ const CXXRecordDecl &ClassDecl,
  const CXXConstructorDecl *Ctor);
 
   // A subtle side effect of Type.6 part 2:
   // Make sure to initialize trivially constructible base classes.
   void checkMissingBaseClassInitializer(const ASTContext &Context,
+const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor);
 
   // Checks Type.6 part 2:
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -32,17 +32,17 @@
 // the record type (or indirect field) is a union, forEachField will stop after
 // the first field.
 template 
-void forEachField(const RecordDecl *Record, const T &Fields,
+void forEachField(const RecordDecl &Record, const T &Fields,
   bool OneFieldPerUnion, Func &&Fn) {
   for (const FieldDecl *F : Fields) {
 if (F->isAnonymousStructOrUnion()) {
   if (const CXXRecordDecl *R = F->getType()->getAsCXXRecordDecl())
-forEachField(R, R->fie

[PATCH] D24965: [clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives

2016-10-04 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D24965#560785, @aaron.ballman wrote:

> LGTM, thank you!


I don't have commit access, so please commit this for me.
Thanks.


https://reviews.llvm.org/D24965



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-10-04 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.


> aaron.ballman wrote in readability-redundant-member-init.cpp:162
> Missing a test for `union` member initializers. Also, a test that multiple 
> inheritance doesn't cause a fixit malfunction would be nice.

Note that all the fixits malfunction until https://reviews.llvm.org/D24572 
lands.

https://reviews.llvm.org/D24339



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-10-04 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73479.
malcolm.parsons added a comment.

Add test for initializing a union member.
Add test for multiple inheritance.


https://reviews.llvm.org/D24339

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tidy/readability/RedundantMemberInitCheck.h
  clang-tidy/utils/TypeTraits.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-member-init.rst
  test/clang-tidy/readability-redundant-member-init.cpp

Index: test/clang-tidy/readability-redundant-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-member-init.cpp
@@ -0,0 +1,181 @@
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+
+struct S {
+  S() = default;
+  S(int i) : i(i) {}
+  int i = 1;
+};
+
+struct T {
+  T(int i = 1) : i(i) {}
+  int i;
+};
+
+struct U {
+  int i;
+};
+
+union V {
+  int i;
+  double f;
+};
+
+// Initializer calls default constructor
+struct F1 {
+  F1() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-FIXES: F1() {}
+  S f;
+};
+
+// Initializer calls default constructor with default argument
+struct F2 {
+  F2() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-FIXES: F2() {}
+  T f;
+};
+
+// Multiple redundant initializers for same constructor
+struct F3 {
+  F3() : f(), g(1), h() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: initializer for member 'h' is redundant
+  // CHECK-FIXES: F3() : g(1) {}
+  S f, g, h;
+};
+
+// Templated class independent type
+template 
+struct F4 {
+  F4() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-FIXES: F4() {}
+  S f;
+};
+F4 f4i;
+F4 f4s;
+
+// Base class
+struct F5 : S {
+  F5() : S() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant
+  // CHECK-FIXES: F5() {}
+};
+
+// Constructor call requires cleanup
+struct Cleanup {
+  ~Cleanup() {}
+};
+
+struct UsesCleanup {
+  UsesCleanup(const Cleanup &c = Cleanup()) {}
+};
+
+struct F6 {
+  F6() : uc() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'uc' is redundant
+  // CHECK-FIXES: F6() {}
+  UsesCleanup uc;
+};
+
+// Multiple inheritance
+struct F7 : S, T {
+  F7() : S(), T() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant
+  // CHECK-MESSAGES: :[[@LINE-2]]:15: warning: initializer for base class 'T' is redundant
+  // CHECK-FIXES: F7() {}
+};
+
+// Initializer not written
+struct NF1 {
+  NF1() {}
+  S f;
+};
+
+// Initializer doesn't call default constructor
+struct NF2 {
+  NF2() : f(1) {}
+  S f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF3 {
+  NF3() : f(1) {}
+  T f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF4 {
+  NF4() : f(2) {}
+  T f;
+};
+
+// Initializer is zero-initialization
+struct NF5 {
+  NF5() : i() {}
+  int i;
+};
+
+// Initializer is direct-initialization
+struct NF6 {
+  NF6() : i(1) {}
+  int i;
+};
+
+// Initializer is aggregate initialization of struct
+struct NF7 {
+  NF7() : f{} {}
+  U f;
+};
+
+// Initializer is zero-initialization of struct
+struct NF7b {
+  NF7b() : f() {}
+  U f;
+};
+
+// Initializer is aggregate initialization of array
+struct NF8 {
+  NF8() : f{} {}
+  int f[2];
+};
+
+struct NF9 {
+  NF9() : f{} {}
+  S f[2];
+};
+
+// Initializing member of union
+union NF10 {
+  NF10() : s() {}
+  int i;
+  S s;
+};
+
+// Templated class dependent type
+template 
+struct NF11 {
+  NF11() : f() {}
+  V f;
+};
+NF11 nf11i;
+NF11 nf11s;
+
+// Delegating constructor
+class NF12 {
+  NF12() = default;
+  NF12(int) : NF12() {}
+};
+
+// Const member
+struct NF13 {
+  NF13() : f() {}
+  const S f;
+};
+
+// Union member
+struct NF14 {
+  NF14() : f() {}
+  V f;
+};
Index: docs/clang-tidy/checks/readability-redundant-member-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-member-init.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - readability-redundant-member-init
+
+readability-redundant-member-init
+=
+
+Finds member initializations that are unnecessary because the same default
+constructor would be called if they were not present.
+
+Example:
+
+.. code-block:: c++
+
+  // Explicitly initializing the member s is unnecessary.
+  class Foo {
+  public:
+Foo() : s() {}
+
+  private:
+std::string s;
+  };
Index: docs/clang-tidy/checks/list.rst
===

[PATCH] D25238: [clang-tidy] Ignore empty members and bases in cppcoreguidelines-pro-type-member-init

2016-10-04 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, alexfh, mgehre.
malcolm.parsons added a subscriber: cfe-commits.
Herald added a subscriber: nemanjai.

Empty/incomplete variables/members/bases don't need to be initialized


https://reviews.llvm.org/D25238

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp


Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -423,3 +423,30 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: G
+
+struct NegativeEmpty {
+};
+
+static void NegativeEmptyVar() {
+  NegativeEmpty e;
+  (void)e;
+}
+
+struct NegativeEmptyMember {
+  NegativeEmptyMember() {}
+  NegativeEmpty e;
+};
+
+struct NegativeEmptyBase : NegativeEmpty {
+  NegativeEmptyBase() {}
+};
+
+struct NegativeEmptyArrayMember {
+  NegativeEmptyArrayMember() {}
+  char e[0];
+};
+
+struct NegativeIncompleteArrayMember {
+  NegativeIncompleteArrayMember() {}
+  char e[];
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -317,6 +317,28 @@
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// copied from clang/lib/Sema/SemaDeclCXX.cpp
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) 
{
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor) {
@@ -330,7 +352,8 @@
   forEachField(ClassDecl, ClassDecl.fields(), false, [&](const FieldDecl *F) {
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
-Context))
+Context) &&
+!isEmpty(Context, F->getType()))
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())


Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -423,3 +423,30 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
+
+struct NegativeEmpty {
+};
+
+static void NegativeEmptyVar() {
+  NegativeEmpty e;
+  (void)e;
+}
+
+struct NegativeEmptyMember {
+  NegativeEmptyMember() {}
+  NegativeEmpty e;
+};
+
+struct NegativeEmptyBase : NegativeEmpty {
+  NegativeEmptyBase() {}
+};
+
+struct NegativeEmptyArrayMember {
+  NegativeEmptyArrayMember() {}
+  char e[0];
+};
+
+struct NegativeIncompleteArrayMember {
+  NegativeIncompleteArrayMember() {}
+  char e[];
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -317,6 +317,28 @@
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// copied from clang/lib/Sema/SemaDeclCXX.cpp
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) {
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-06 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: angelgarcia, aaron.ballman, klimek.
malcolm.parsons added subscribers: cfe-commits, Eugene.Zelenko.

Extend modernize-use-auto to cases when variable is assigned with cast.

e.g.
Type *Ptr1 = dynamic_cast(Ptr2);


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+  
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b6 = static_cast(a);
+  auto &b7 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = reinterpret_cast(*a);
+}
+
+void f_const_cast() {
+  const A *a1 = new A();
+  A *a2 = const_cast(a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *a2 = const_cast(a1);
+  A &a3 = const_cast(*a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &a3 = const_cast(*a1);
+}
+
+void f_cstyle_cast() {
+  auto *a = new A();
+  C *c1 = (C *)a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = (C *)a;
+
+  C &c2 = (C &)*a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = (C &)*a;
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -0,0 +1,91 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: '1'}]}" \
+// RUN:   -- -std=c++11
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-06 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73780.
malcolm.parsons added a comment.

Add functional casts to tests and doc.


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,100 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+  
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b6 = static_cast(a);
+  auto &b7 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = reinterpret_cast(*a);
+}
+
+void f_const_cast() {
+  const A *a1 = new A();
+  A *a2 = const_cast(a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *a2 = const_cast(a1);
+  A &a3 = const_cast(*a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &a3 = const_cast(*a1);
+}
+
+void f_cstyle_cast() {
+  auto *a = new A();
+  C *c1 = (C *)a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = (C *)a;
+
+  C &c2 = (C &)*a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = (C &)*a;
+}
+
+void f_functional_cast() {
+  long l = 1;
+  int i1 = int(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = int(l);
+
+  B b;
+  A a = A(b);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -0,0 +1,101 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: '1'}]}" \
+// RUN:   -- -std=c++11
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHEC

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-06 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D25316#563654, @Eugene.Zelenko wrote:

> I think will be good idea to handle LLVM casts and getAs<> methods too. There 
> are plenty of them in LLVM/Clang/etc code used for variable initialization.


Yes.
I plan to do that, but maybe in another changeset.


https://reviews.llvm.org/D25316



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-06 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73831.
malcolm.parsons added a comment.

Mention in release notes.


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,100 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+  
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b6 = static_cast(a);
+  auto &b7 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = reinterpret_cast(*a);
+}
+
+void f_const_cast() {
+  const A *a1 = new A();
+  A *a2 = const_cast(a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *a2 = const_cast(a1);
+  A &a3 = const_cast(*a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &a3 = const_cast(*a1);
+}
+
+void f_cstyle_cast() {
+  auto *a = new A();
+  C *c1 = (C *)a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = (C *)a;
+
+  C &c2 = (C &)*a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = (C &)*a;
+}
+
+void f_functional_cast() {
+  long l = 1;
+  int i1 = int(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = int(l);
+
+  B b;
+  A a = A(b);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -0,0 +1,101 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: '1'}]}" \
+// RUN:   -- -std=c++11
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-07 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D25316#563930, @Prazek wrote:

> Please add tests with
>
>   long long p = static_cast(4);
>   
>
> and the same with const at beginning. I remember I had problems with this 
> last time (Type->SourceRange was returning only source range for the first 
> token.


BuiltinTypeLoc only returns the first token:

  SourceRange getLocalSourceRange() const {
return SourceRange(getBuiltinLoc(), getBuiltinLoc());
  }

The existing check fails too:

  -long long *ll = new long long();
  +auto long *ll = new long long();


https://reviews.llvm.org/D25316



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-07 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added a reviewer: Prazek.
malcolm.parsons added a subscriber: cfe-commits.

clang-tidy's modernize-use-auto check uses the SourceRange of a
TypeLoc when replacing the type with auto.
This was producing the wrong result for multi-token builtin types
like long long:

-long long *ll = new long long();
+auto long *ll = new long long();


https://reviews.llvm.org/D25363

Files:
  include/clang/AST/TypeLoc.h
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaType.cpp


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4920,10 +4920,10 @@
 // Try to have a meaningful source location.
 if (TL.getWrittenSignSpec() != TSS_unspecified)
   // Sign spec loc overrides the others (e.g., 'unsigned long').
-  TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
+  TL.setBuiltinLocStart(DS.getTypeSpecSignLoc());
 else if (TL.getWrittenWidthSpec() != TSW_unspecified)
   // Width spec loc overrides type spec loc (e.g., 'short int').
-  TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
+  TL.setBuiltinLocStart(DS.getTypeSpecWidthLoc());
   }
 }
 void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -618,6 +618,8 @@
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSTLoc = Loc;
   return false;
 }
 
Index: include/clang/AST/TypeLoc.h
===
--- include/clang/AST/TypeLoc.h
+++ include/clang/AST/TypeLoc.h
@@ -510,7 +510,7 @@
 
 
 struct BuiltinLocInfo {
-  SourceLocation BuiltinLoc;
+  SourceRange BuiltinRange;
 };
 
 /// \brief Wrapper for source info for builtin types.
@@ -520,10 +520,17 @@
   BuiltinLocInfo> {
 public:
   SourceLocation getBuiltinLoc() const {
-return getLocalData()->BuiltinLoc;
+return getLocalData()->BuiltinRange.getBegin();
   }
   void setBuiltinLoc(SourceLocation Loc) {
-getLocalData()->BuiltinLoc = Loc;
+getLocalData()->BuiltinRange = {Loc, Loc};
+  }
+  void setBuiltinLocStart(SourceLocation Loc) {
+if (getLocalData()->BuiltinRange.getEnd().isValid()) {
+  getLocalData()->BuiltinRange.setBegin(Loc);
+} else {
+  setBuiltinLoc(Loc);
+}
   }
 
   SourceLocation getNameLoc() const { return getBuiltinLoc(); }
@@ -552,7 +559,7 @@
   }
 
   SourceRange getLocalSourceRange() const {
-return SourceRange(getBuiltinLoc(), getBuiltinLoc());
+return getLocalData()->BuiltinRange;
   }
 
   TypeSpecifierSign getWrittenSignSpec() const {


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4920,10 +4920,10 @@
 // Try to have a meaningful source location.
 if (TL.getWrittenSignSpec() != TSS_unspecified)
   // Sign spec loc overrides the others (e.g., 'unsigned long').
-  TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
+  TL.setBuiltinLocStart(DS.getTypeSpecSignLoc());
 else if (TL.getWrittenWidthSpec() != TSW_unspecified)
   // Width spec loc overrides type spec loc (e.g., 'short int').
-  TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
+  TL.setBuiltinLocStart(DS.getTypeSpecWidthLoc());
   }
 }
 void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -618,6 +618,8 @@
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSTLoc = Loc;
   return false;
 }
 
Index: include/clang/AST/TypeLoc.h
===
--- include/clang/AST/TypeLoc.h
+++ include/clang/AST/TypeLoc.h
@@ -510,7 +510,7 @@
 
 
 struct BuiltinLocInfo {
-  SourceLocation BuiltinLoc;
+  SourceRange BuiltinRange;
 };
 
 /// \brief Wrapper for source info for builtin types.
@@ -520,10 +520,17 @@
   BuiltinLocInfo> {
 public:
   SourceLocation getBuiltinLoc() const {
-return getLocalData()->BuiltinLoc;
+return getLocalData()->BuiltinRange.getBegin();
   }
   void setBuiltinLoc(SourceLocation Loc) {
-getLocalData()->BuiltinLoc = Loc;
+getLocalData()->BuiltinRange = {Loc, Loc};
+  }
+  void setBuiltinLocStart(SourceLocation Loc) {
+if (getLocalData()->BuiltinRange.getEnd().isValid()) {
+  getLocalData()->BuiltinRange.setBegin(Loc);
+} e

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-07 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 73918.
malcolm.parsons added a comment.

Add more tests.


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -15,6 +15,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
   // CHECK-FIXES: static auto *a_static = new MyType();
 
+  long long *ll = new long long();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
+  // CHECK-FIXES: auto *ll = new long long();
+
   MyType *derived = new MyDerivedType();
 
   void *vd = new MyType();
Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,113 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  long long ll = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ll = static_cast(l);
+  unsigned long long ull = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ull = static_cast(l);
+  unsigned int ui = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ui = static_cast(l);
+  long double ld = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ld = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+  
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b6 = static_cast(a);
+  auto &b7 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &c2 = reinterpret_cast(*a);
+}
+
+void f_const_cast() {
+  const A *a1 = new A();
+  A *a2 = const_cast(a1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-08 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74022.
malcolm.parsons added a comment.

Rework handling of references


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -15,6 +15,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
   // CHECK-FIXES: static auto *a_static = new MyType();
 
+  long long *ll = new long long();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
+  // CHECK-FIXES: auto *ll = new long long();
+
   MyType *derived = new MyDerivedType();
 
   void *vd = new MyType();
Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,117 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  long long ll = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ll = static_cast(l);
+  unsigned long long ull = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ull = static_cast(l);
+  unsigned int ui = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ui = static_cast(l);
+  long double ld = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ld = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+
+  B &b6 = static_cast(*a), &b7 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b6 = static_cast(*a), &b7 = static_cast(*a);
+
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b8 = static_cast(a);
+  auto &b9 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHE

[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-08 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D25363#565371, @Prazek wrote:

> Thanks for the patch! I think some unit test should be added.


Are there any existing unit tests for TypeLoc that I can add to?

> Do you also handle cases like
> 
>   unsigned long long

Yes - see tests in https://reviews.llvm.org/D25316.

> The problem here is that the whole type like "unsigned long long" could be in 
> other tokens. 
>  I talked with Richard Smith while ago and one of the solutions proposed was 
> to have "isValid()" for source range
>  returning false for cases like this
> 
>   unsigned const long

I see.  I hope that's a rare case that I can ignore for now.




Comment at: lib/Sema/DeclSpec.cpp:621
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSTLoc = Loc;

Prazek wrote:
> What about cases like 
>   unsigned int
>   unsigned long
> 
> This is not only about long.
for `unsigned int`, `DeclSpec::SetTypeSpecSign()` sets `TSSLoc` to the location 
of `unsigned` and `DeclSpec::SetTypeSpecType()` sets `TSTLoc` to the location 
of `int` so `VisitBuiltinTypeLoc()` already has the whole range available.

for `unsigned long`, `DeclSpec::SetTypeSpecSign()` sets `TSSLoc` to the 
location of `unsigned` and `DeclSpec::SetTypeSpecWidth()` sets `TSWLoc` to the 
location of `long` so `VisitBuiltinTypeLoc()` already has the whole range 
available.

The sign and type parts can't appear more than once, but the width part can.
I'm treating the final width part as being the type part.
This works for `long long` and `long long int`, but it looks like it would have 
issues with `int long long`.
Maybe TSWLoc should be replaced by a range.


https://reviews.llvm.org/D25363



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-08 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D25316#565378, @Prazek wrote:

> Awesome to see this patch. After this one will make it to upstream, it will 
> be much easier for me to do same with template functions.


I was trying to match such functions:

  varDecl(hasType(type().bind("type")),
  hasInitializer(callExpr(callee(
  functionDecl(isInstantiated(),
   hasTemplateArgument(
   0, refersToType(type(equalsBoundNode("type")
  .bind("fn")




Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:2
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, 
value: '1'}]}" \
+// RUN:   -- -std=c++11

Prazek wrote:
> What is the difference between this test, and next test?
> The name indicate that it removes star, but I see a lot of test that doesn't 
> use star
> and that seem to be duplicated with the next one.
I could remove the duplicated tests, but the expected fixes are different so 
I'd like to test with and without star removal.



Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:25
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  ll = static_cast(l);
+  unsigned long long ull = static_cast(l);

Prazek wrote:
> Is it possible to simply fix the double spaces?
The existing modernize-use-auto tests have the same problem.
My codebase is clang-formatted regularly so it doesn't bother me.


https://reviews.llvm.org/D25316



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-08 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74047.
malcolm.parsons added a comment.

Replace TSWLoc with TSWRange


https://reviews.llvm.org/D25363

Files:
  include/clang/AST/TypeLoc.h
  include/clang/Sema/DeclSpec.h
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaType.cpp

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4919,11 +4919,9 @@
 TL.getWrittenBuiltinSpecs() = DS.getWrittenBuiltinSpecs();
 // Try to have a meaningful source location.
 if (TL.getWrittenSignSpec() != TSS_unspecified)
-  // Sign spec loc overrides the others (e.g., 'unsigned long').
   TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
-else if (TL.getWrittenWidthSpec() != TSW_unspecified)
-  // Width spec loc overrides type spec loc (e.g., 'short int').
-  TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
+if (TL.getWrittenWidthSpec() != TSW_unspecified)
+  TL.setBuiltinRange(DS.getTypeSpecWidthRange());
   }
 }
 void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -610,14 +610,16 @@
 const char *&PrevSpec,
 unsigned &DiagID,
 const PrintingPolicy &Policy) {
-  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
+  // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
   // for 'long long' we will keep the source location of the first 'long'.
   if (TypeSpecWidth == TSW_unspecified)
-TSWLoc = Loc;
+TSWRange.setBegin(Loc);
   // Allow turning long -> long long.
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSWRange.setEnd(Loc);
   return false;
 }
 
@@ -997,9 +999,9 @@
TypeQualifiers)) {
 const unsigned NumLocs = 9;
 SourceLocation ExtraLocs[NumLocs] = {
-  TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
-  TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc
-};
+TSWRange.getBegin(), TSCLoc,   TSSLoc,
+AltiVecLoc,  TQ_constLoc,  TQ_restrictLoc,
+TQ_volatileLoc,  TQ_atomicLoc, TQ_unalignedLoc};
 FixItHint Hints[NumLocs];
 SourceLocation FirstLoc;
 for (unsigned I = 0; I != NumLocs; ++I) {
@@ -1041,8 +1043,8 @@
   // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
   if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) &&
   (TypeSpecWidth != TSW_longlong))
-S.Diag(TSWLoc, diag::err_invalid_vector_bool_decl_spec)
-  << getSpecifierName((TSW)TypeSpecWidth);
+S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
+<< getSpecifierName((TSW)TypeSpecWidth);
 
   // vector bool long long requires VSX support or ZVector.
   if ((TypeSpecWidth == TSW_longlong) &&
@@ -1059,7 +1061,8 @@
   // vector long double and vector long long double are never allowed.
   // vector double is OK for Power7 and later, and ZVector.
   if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
-S.Diag(TSWLoc, diag::err_invalid_vector_long_double_decl_spec);
+S.Diag(TSWRange.getBegin(),
+   diag::err_invalid_vector_long_double_decl_spec);
   else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
!S.getLangOpts().ZVector)
 S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
@@ -1070,10 +1073,11 @@
 } else if (TypeSpecWidth == TSW_long) {
   // vector long is unsupported for ZVector and deprecated for AltiVec.
   if (S.getLangOpts().ZVector)
-S.Diag(TSWLoc, diag::err_invalid_vector_long_decl_spec);
+S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
   else
-S.Diag(TSWLoc, diag::warn_vector_long_decl_spec_combination)
-  << getSpecifierName((TST)TypeSpecType, Policy);
+S.Diag(TSWRange.getBegin(),
+   diag::warn_vector_long_decl_spec_combination)
+<< getSpecifierName((TST)TypeSpecType, Policy);
 }
 
 if (TypeAltiVecPixel) {
@@ -1106,18 +1110,18 @@
 if (TypeSpecType == TST_unspecified)
   TypeSpecType = TST_int; // short -> short int, long long -> long long int.
 else if (TypeSpecType != TST_int) {
-  S.Diag(TSWLoc, diag::err_invalid_width_spec) << (int)TypeSpecWidth
-<<  getSpecifierName((TST)TypeSpecType, Policy);
+  S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
+  << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
   TypeSpecType = TST_int;
   TypeSpecOwned = false;
 }
 break;
   case TSW_lon

[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-08 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

I've tested this with clang-query using `match typeLoc()` and a lot of 
permutations of int, short, long, unsigned, and const.


https://reviews.llvm.org/D25363



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-09 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D25316#565567, @Prazek wrote:

>   functionDecl(hasName(LEXICAL_CAST_NAME),


I was trying to avoid specifying the name of the function so that it works for 
any templated function/member function that returns its first template type.




Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:25
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  ll = static_cast(l);
+  unsigned long long ull = static_cast(l);

Prazek wrote:
> malcolm.parsons wrote:
> > Prazek wrote:
> > > Is it possible to simply fix the double spaces?
> > The existing modernize-use-auto tests have the same problem.
> > My codebase is clang-formatted regularly so it doesn't bother me.
> I agree that it is not huge problem with clang-format and of course it is not 
> required to fix it to push this patch upstream. It would be good to leave a 
> comment somewhere with FIXME: about this, so it would be easier for some 
> other contributor to fix it (or if it simple, just fix it in this patch :))
There's a FIXME comment in one of the existing modernize-use-auto test files.


https://reviews.llvm.org/D25316



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74117.
malcolm.parsons added a comment.

Ensure SourceRange is initialized


https://reviews.llvm.org/D25363

Files:
  include/clang/AST/TypeLoc.h
  include/clang/Sema/DeclSpec.h
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaType.cpp

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4919,11 +4919,9 @@
 TL.getWrittenBuiltinSpecs() = DS.getWrittenBuiltinSpecs();
 // Try to have a meaningful source location.
 if (TL.getWrittenSignSpec() != TSS_unspecified)
-  // Sign spec loc overrides the others (e.g., 'unsigned long').
-  TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
-else if (TL.getWrittenWidthSpec() != TSW_unspecified)
-  // Width spec loc overrides type spec loc (e.g., 'short int').
-  TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
+  TL.expandBuiltinRange(DS.getTypeSpecSignLoc());
+if (TL.getWrittenWidthSpec() != TSW_unspecified)
+  TL.expandBuiltinRange(DS.getTypeSpecWidthRange());
   }
 }
 void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -610,14 +610,16 @@
 const char *&PrevSpec,
 unsigned &DiagID,
 const PrintingPolicy &Policy) {
-  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
+  // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
   // for 'long long' we will keep the source location of the first 'long'.
   if (TypeSpecWidth == TSW_unspecified)
-TSWLoc = Loc;
+TSWRange.setBegin(Loc);
   // Allow turning long -> long long.
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSWRange.setEnd(Loc);
   return false;
 }
 
@@ -997,9 +999,9 @@
TypeQualifiers)) {
 const unsigned NumLocs = 9;
 SourceLocation ExtraLocs[NumLocs] = {
-  TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
-  TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc
-};
+TSWRange.getBegin(), TSCLoc,   TSSLoc,
+AltiVecLoc,  TQ_constLoc,  TQ_restrictLoc,
+TQ_volatileLoc,  TQ_atomicLoc, TQ_unalignedLoc};
 FixItHint Hints[NumLocs];
 SourceLocation FirstLoc;
 for (unsigned I = 0; I != NumLocs; ++I) {
@@ -1041,8 +1043,8 @@
   // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
   if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) &&
   (TypeSpecWidth != TSW_longlong))
-S.Diag(TSWLoc, diag::err_invalid_vector_bool_decl_spec)
-  << getSpecifierName((TSW)TypeSpecWidth);
+S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
+<< getSpecifierName((TSW)TypeSpecWidth);
 
   // vector bool long long requires VSX support or ZVector.
   if ((TypeSpecWidth == TSW_longlong) &&
@@ -1059,7 +1061,8 @@
   // vector long double and vector long long double are never allowed.
   // vector double is OK for Power7 and later, and ZVector.
   if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
-S.Diag(TSWLoc, diag::err_invalid_vector_long_double_decl_spec);
+S.Diag(TSWRange.getBegin(),
+   diag::err_invalid_vector_long_double_decl_spec);
   else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
!S.getLangOpts().ZVector)
 S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
@@ -1070,10 +1073,11 @@
 } else if (TypeSpecWidth == TSW_long) {
   // vector long is unsupported for ZVector and deprecated for AltiVec.
   if (S.getLangOpts().ZVector)
-S.Diag(TSWLoc, diag::err_invalid_vector_long_decl_spec);
+S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
   else
-S.Diag(TSWLoc, diag::warn_vector_long_decl_spec_combination)
-  << getSpecifierName((TST)TypeSpecType, Policy);
+S.Diag(TSWRange.getBegin(),
+   diag::warn_vector_long_decl_spec_combination)
+<< getSpecifierName((TST)TypeSpecType, Policy);
 }
 
 if (TypeAltiVecPixel) {
@@ -1106,18 +1110,18 @@
 if (TypeSpecType == TST_unspecified)
   TypeSpecType = TST_int; // short -> short int, long long -> long long int.
 else if (TypeSpecType != TST_int) {
-  S.Diag(TSWLoc, diag::err_invalid_width_spec) << (int)TypeSpecWidth
-<<  getSpecifierName((TST)TypeSpecType, Policy);
+  S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
+  << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
   TypeSpecType = TST_in

[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74124.
malcolm.parsons added a comment.

Add unit tests


https://reviews.llvm.org/D25363

Files:
  include/clang/AST/TypeLoc.h
  include/clang/Sema/DeclSpec.h
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaType.cpp
  unittests/AST/SourceLocationTest.cpp

Index: unittests/AST/SourceLocationTest.cpp
===
--- unittests/AST/SourceLocationTest.cpp
+++ unittests/AST/SourceLocationTest.cpp
@@ -148,6 +148,84 @@
  varDecl(), Lang_C89));
 }
 
+TEST(TypeLoc, IntRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 1);
+  EXPECT_TRUE(Verifier.match("int a;", typeLoc()));
+}
+
+TEST(TypeLoc, LongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 1);
+  EXPECT_TRUE(Verifier.match("long a;", typeLoc()));
+}
+
+TEST(TypeLoc, LongIntRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 6);
+  EXPECT_TRUE(Verifier.match("long int a;", typeLoc()));
+}
+
+TEST(TypeLoc, IntLongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 5);
+  EXPECT_TRUE(Verifier.match("int long a;", typeLoc()));
+}
+
+TEST(TypeLoc, UnsignedIntRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 10);
+  EXPECT_TRUE(Verifier.match("unsigned int a;", typeLoc()));
+}
+
+TEST(TypeLoc, IntUnsignedRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 5);
+  EXPECT_TRUE(Verifier.match("int unsigned a;", typeLoc()));
+}
+
+TEST(TypeLoc, LongLongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 6);
+  EXPECT_TRUE(Verifier.match("long long a;", typeLoc()));
+}
+
+TEST(TypeLoc, UnsignedLongLongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 15);
+  EXPECT_TRUE(Verifier.match("unsigned long long a;", typeLoc()));
+}
+
+TEST(TypeLoc, LongUnsignedLongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 15);
+  EXPECT_TRUE(Verifier.match("long unsigned long a;", typeLoc()));
+}
+
+TEST(TypeLoc, LongLongUnsignedRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 11);
+  EXPECT_TRUE(Verifier.match("long long unsigned a;", typeLoc()));
+}
+
+TEST(TypeLoc, ConstLongLongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 7, 1, 12);
+  EXPECT_TRUE(Verifier.match("const long long a = 0;", typeLoc()));
+}
+
+TEST(TypeLoc, LongConstLongRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 12);
+  EXPECT_TRUE(Verifier.match("long const long a = 0;", typeLoc()));
+}
+
+TEST(TypeLoc, LongLongConstRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 6);
+  EXPECT_TRUE(Verifier.match("long long const a = 0;", typeLoc()));
+}
+
 TEST(CXXConstructorDecl, NoRetFunTypeLocRange) {
   RangeVerifier Verifier;
   Verifier.expectRange(1, 11, 1, 13);
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4919,11 +4919,9 @@
 TL.getWrittenBuiltinSpecs() = DS.getWrittenBuiltinSpecs();
 // Try to have a meaningful source location.
 if (TL.getWrittenSignSpec() != TSS_unspecified)
-  // Sign spec loc overrides the others (e.g., 'unsigned long').
-  TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
-else if (TL.getWrittenWidthSpec() != TSW_unspecified)
-  // Width spec loc overrides type spec loc (e.g., 'short int').
-  TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
+  TL.expandBuiltinRange(DS.getTypeSpecSignLoc());
+if (TL.getWrittenWidthSpec() != TSW_unspecified)
+  TL.expandBuiltinRange(DS.getTypeSpecWidthRange());
   }
 }
 void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -610,14 +610,16 @@
 const char *&PrevSpec,
 unsigned &DiagID,
 const PrintingPolicy &Policy) {
-  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
+  // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
   // for 'long long' we will keep the source location of the first 'long'.
   if (TypeSpecWidth == TSW_unspecified)
-TSWLoc = Loc;
+TSWRange.setBegin(Loc);
   // Allow turning long -> long long.
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSWRange.setEnd(Loc);
   return false;
 }
 
@@ -997,9 +999,9 @@
TypeQualifiers)) {
 const unsigned NumLocs = 9;
 SourceLocation ExtraLocs[NumLocs] = {
-  TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
-  TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc
-};
+TSWRange.getBegin(), TSC

[PATCH] D25238: [clang-tidy] Ignore empty members and bases in cppcoreguidelines-pro-type-member-init

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74125.
malcolm.parsons added a comment.

Mark comment as FIXME.


https://reviews.llvm.org/D25238

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp


Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -423,3 +423,30 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: G
+
+struct NegativeEmpty {
+};
+
+static void NegativeEmptyVar() {
+  NegativeEmpty e;
+  (void)e;
+}
+
+struct NegativeEmptyMember {
+  NegativeEmptyMember() {}
+  NegativeEmpty e;
+};
+
+struct NegativeEmptyBase : NegativeEmpty {
+  NegativeEmptyBase() {}
+};
+
+struct NegativeEmptyArrayMember {
+  NegativeEmptyArrayMember() {}
+  char e[0];
+};
+
+struct NegativeIncompleteArrayMember {
+  NegativeIncompleteArrayMember() {}
+  char e[];
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -317,6 +317,28 @@
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) 
{
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor) {
@@ -330,7 +352,8 @@
   forEachField(ClassDecl, ClassDecl.fields(), false, [&](const FieldDecl *F) {
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
-Context))
+Context) &&
+!isEmpty(Context, F->getType()))
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())


Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -423,3 +423,30 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
+
+struct NegativeEmpty {
+};
+
+static void NegativeEmptyVar() {
+  NegativeEmpty e;
+  (void)e;
+}
+
+struct NegativeEmptyMember {
+  NegativeEmptyMember() {}
+  NegativeEmpty e;
+};
+
+struct NegativeEmptyBase : NegativeEmpty {
+  NegativeEmptyBase() {}
+};
+
+struct NegativeEmptyArrayMember {
+  NegativeEmptyArrayMember() {}
+  char e[0];
+};
+
+struct NegativeIncompleteArrayMember {
+  NegativeIncompleteArrayMember() {}
+  char e[];
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -317,6 +317,28 @@
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) {
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor) {
@@ -330,7 +352,8 @@
   forEachField(ClassDecl, ClassDecl.fields(), false, [&](const FieldDecl *F) {

[PATCH] D25316: [clang-tidy] Enhance modernize-use-auto to casts

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:346
 
-const auto *NewExpr = 
cast(V->getInit()->IgnoreParenImpCasts());
-// Ensure that every VarDecl has a CXXNewExpr initializer.
-if (!NewExpr)
+const auto *Expr = cast(V->getInit()->IgnoreParenImpCasts());
+// Ensure that every VarDecl has an ExprType initializer.

aaron.ballman wrote:
> I think you should use `dyn_cast` here because `ExprType` may vary from call 
> to call and produce an invalid cast otherwise.
The `cast` was safe in the existing check because `makeDeclWithNewMatcher` 
creates a matcher that ensures all initializers are `CxxNewExpr`. 
`makeDeclWithCastMatcher` needs to be fixed.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:404
  Result.Nodes.getNodeAs(DeclWithNewId)) {
-replaceNew(Decl, Result.Context);
+auto GetType = [](const CXXNewExpr *Expr) {
+  return Expr->getType();

aaron.ballman wrote:
> Just inline the lambda expression (below as well).
OK.



Comment at: clang-tidy/modernize/UseAutoCheck.h:30
+  void replaceExpr(const DeclStmt *D, ASTContext *Context, TypeFn GetType,
+   StringRef message);
 

aaron.ballman wrote:
> s/message/Message
Oops.



Comment at: docs/clang-tidy/checks/modernize-use-auto.rst:150
+Frequently, when a variable is declared and initialized with a cast, the
+variable type has to be written twice: in the declaration type and in the
+cast expression. In this cases, the declaration type can be replaced with

aaron.ballman wrote:
> s/has to be/is
It's a copy and paste from the section above; I'll fix both.



Comment at: docs/clang-tidy/checks/modernize-use-auto.rst:164-165
+``reinterpret_cast``, functional casts and c style casts.
+It does not handle function templates that behave as casts, such as
+``llvm::dyn_cast``, ``boost::lexical_cast`` or ``gsl::narrow_cast``.
+

aaron.ballman wrote:
> Should this be moved into Known Limitations?
OK.


https://reviews.llvm.org/D25316



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25406: Fix doubled whitespace in modernize-use-auto fixit

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74131.
malcolm.parsons added a comment.

Only insert whitespace when removing stars


https://reviews.llvm.org/D25406

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  test/clang-tidy/modernize-use-auto-new-remove-stars.cpp

Index: test/clang-tidy/modernize-use-auto-new-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-new-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-new-remove-stars.cpp
@@ -6,8 +6,6 @@
 
 class MyDerivedType : public MyType {};
 
-// FIXME: the replacement sometimes results in two consecutive spaces after
-// the word 'auto' (due to the presence of spaces at both sides of '*').
 void auto_new() {
   MyType *a_new = new MyType();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
@@ -29,15 +27,15 @@
   // not "MyType * const".
   static MyType * const d_static = new MyType();
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
-  // CHECK-FIXES: static auto  const d_static = new MyType();
+  // CHECK-FIXES: static auto const d_static = new MyType();
 
   MyType * const a_const = new MyType();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
-  // CHECK-FIXES: auto  const a_const = new MyType();
+  // CHECK-FIXES: auto const a_const = new MyType();
 
   MyType * volatile vol = new MyType();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
-  // CHECK-FIXES: auto  volatile vol = new MyType();
+  // CHECK-FIXES: auto volatile vol = new MyType();
 
   struct SType {} *stype = new SType;
 
@@ -81,15 +79,15 @@
 
 int_p a = new int;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use auto when initializing with new
-// CHECK-FIXES: auto  a = new int;
+// CHECK-FIXES: auto a = new int;
 int_p *b = new int*;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use auto when initializing with new
 // CHECK-FIXES: auto b = new int*;
 
 // Test for typedefs in declarations lists.
 int_p c = new int, d = new int;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use auto when initializing with new
-// CHECK-FIXES: auto  c = new int, d = new int;
+// CHECK-FIXES: auto c = new int, d = new int;
 
 // Different types should not be transformed.
 int_p e = new int, *f = new int_p;
Index: clang-tidy/modernize/UseAutoCheck.h
===
--- clang-tidy/modernize/UseAutoCheck.h
+++ clang-tidy/modernize/UseAutoCheck.h
@@ -25,7 +25,7 @@
 
 private:
   void replaceIterators(const DeclStmt *D, ASTContext *Context);
-  void replaceNew(const DeclStmt *D, ASTContext *Context);
+  void replaceNew(const DeclStmt *D, ASTContext *Context, SourceManager &SM);
 
   const bool RemoveStars;
 };
Index: clang-tidy/modernize/UseAutoCheck.cpp
===
--- clang-tidy/modernize/UseAutoCheck.cpp
+++ clang-tidy/modernize/UseAutoCheck.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang;
 using namespace clang::ast_matchers;
@@ -313,7 +314,8 @@
   << FixItHint::CreateReplacement(Range, "auto");
 }
 
-void UseAutoCheck::replaceNew(const DeclStmt *D, ASTContext *Context) {
+void UseAutoCheck::replaceNew(const DeclStmt *D, ASTContext *Context,
+  SourceManager &SM) {
   const auto *FirstDecl = dyn_cast(*D->decl_begin());
   // Ensure that there is at least one VarDecl within the DeclStmt.
   if (!FirstDecl)
@@ -371,18 +373,23 @@
   auto Diag = diag(Range.getBegin(), "use auto when initializing with new"
  " to avoid duplicating the type name");
 
+  SourceLocation Next =
+  Lexer::getLocForEndOfToken(Range.getEnd(), 0, SM, Context->getLangOpts());
+  bool Whitespace = isWhitespace(*FullSourceLoc(Next, SM).getCharacterData());
+
   // Space after 'auto' to handle cases where the '*' in the pointer type is
   // next to the identifier. This avoids changing 'int *p' into 'autop'.
-  Diag << FixItHint::CreateReplacement(Range, RemoveStars ? "auto " : "auto")
+  Diag << FixItHint::CreateReplacement(
+  Range, (Whitespace || !RemoveStars) ? "auto" : "auto ")
<< StarRemovals;
 }
 
 void UseAutoCheck::check(const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs(IteratorDeclStmtId)) {
 replaceIterators(Decl, Result.Context);
   } else if (const auto *Decl =
  Result.Nodes.getNodeAs(DeclWithNewId)) {
-replaceNew(Decl, Result.Context);
+replaceNew(Decl, Result.Context, *Result.SourceManager);
   } else {
 llvm_unreachable("Bad Callback. No node provided.");
   }
___

[PATCH] D25406: Fix doubled whitespace in modernize-use-auto fixit

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:378
+  Lexer::getLocForEndOfToken(Range.getEnd(), 0, SM, 
Context->getLangOpts());
+  bool Whitespace = isWhitespace(*FullSourceLoc(Next, SM).getCharacterData());
+

aaron.ballman wrote:
> Oye, this is deceptively expensive because you now have to go back to the 
> actual source file for this information. That source file may live on a 
> network share somewhere, for instance.
> 
> Can you use `Token::hasLeadingSpace()` instead?
> 
> Also, doesn't this still need to care about the `RemoveStars` option?
Where would I get a Token from?


https://reviews.llvm.org/D25406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25316: [clang-tidy] Enhance modernize-use-auto to casts

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74134.
malcolm.parsons added a comment.

Fix ast matcher
Add test
Fix parameter case
Inline lambdas
Doc fixes


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -15,6 +15,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
   // CHECK-FIXES: static auto *a_static = new MyType();
 
+  long long *ll = new long long();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
+  // CHECK-FIXES: auto *ll = new long long();
+
   MyType *derived = new MyDerivedType();
 
   void *vd = new MyType();
Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,120 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  long long ll = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ll = static_cast(l);
+  unsigned long long ull = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ull = static_cast(l);
+  unsigned int ui = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ui = static_cast(l);
+  long double ld = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ld = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+
+  B &b6 = static_cast(*a), &b7 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b6 = static_cast(*a), &b7 = static_cast(*a);
+
+  // Don't warn when non-cast involved
+  long double cast = static_cast(l), noncast = 5;
+
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b8 = static_cast(a);
+  auto &b9 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a)

[PATCH] D25316: [clang-tidy] Enhance modernize-use-auto to casts

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons marked 15 inline comments as done.
malcolm.parsons added inline comments.



Comment at: test/clang-tidy/modernize-use-auto-cast.cpp:14
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name

Prazek wrote:
> How do you handle cases like
> 
>   long l = static_cast(i1);
> 
> I would expect it to produce warning, but not produce fixit (because it might 
> change the behavior of program), but I still would like to get information 
> about it because it seems like a bug.
The check requires the VarDecl and Initializer to have the same type, so there 
is no warning.
I don't think this check should warn about it.


https://reviews.llvm.org/D25316



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25316: [clang-tidy] Enhance modernize-use-auto to casts

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74162.
malcolm.parsons added a comment.

Use std::function


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -15,6 +15,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
   // CHECK-FIXES: static auto *a_static = new MyType();
 
+  long long *ll = new long long();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
+  // CHECK-FIXES: auto *ll = new long long();
+
   MyType *derived = new MyDerivedType();
 
   void *vd = new MyType();
Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,120 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  long long ll = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ll = static_cast(l);
+  unsigned long long ull = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ull = static_cast(l);
+  unsigned int ui = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ui = static_cast(l);
+  long double ld = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ld = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+
+  B &b6 = static_cast(*a), &b7 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b6 = static_cast(*a), &b7 = static_cast(*a);
+
+  // Don't warn when non-cast involved
+  long double cast = static_cast(l), noncast = 5;
+
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b8 = static_cast(a);
+  auto &b9 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: us

[PATCH] D25316: [clang-tidy] Enhance modernize-use-auto to casts

2016-10-10 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74163.
malcolm.parsons added a comment.

Really mention in release notes.


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -15,6 +15,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
   // CHECK-FIXES: static auto *a_static = new MyType();
 
+  long long *ll = new long long();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
+  // CHECK-FIXES: auto *ll = new long long();
+
   MyType *derived = new MyDerivedType();
 
   void *vd = new MyType();
Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,120 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  long long ll = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ll = static_cast(l);
+  unsigned long long ull = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ull = static_cast(l);
+  unsigned int ui = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ui = static_cast(l);
+  long double ld = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ld = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+
+  B &b6 = static_cast(*a), &b7 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b6 = static_cast(*a), &b7 = static_cast(*a);
+
+  // Don't warn when non-cast involved
+  long double cast = static_cast(l), noncast = 5;
+
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b8 = static_cast(a);
+  auto &b9 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHEC

[clang-tools-extra] r283865 - Fix typo in documentation

2016-10-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Oct 11 04:42:13 2016
New Revision: 283865

URL: http://llvm.org/viewvc/llvm-project?rev=283865&view=rev
Log:
Fix typo in documentation

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-references.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-references.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-references.rst?rev=283865&r1=283864&r2=283865&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-references.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-references.rst 
Tue Oct 11 04:42:13 2016
@@ -14,4 +14,4 @@ Options
 
 .. option:: WhiteListTypes
 
-   A semicolon-separated list of names of whitelist types. Defualt is empty.
+   A semicolon-separated list of names of whitelist types. Default is empty.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r283869 - [clang-tidy] modernize-use-default default constructor bugfix

2016-10-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Oct 11 05:47:06 2016
New Revision: 283869

URL: http://llvm.org/viewvc/llvm-project?rev=283869&view=rev
Log:
[clang-tidy] modernize-use-default default constructor bugfix

Summary:
Only member initializers that are written should prevent
using '= default' on a default constructor.

Reviewers: klimek, sbenza, aaron.ballman, alexfh

Subscribers: Eugene.Zelenko, alexfh, klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D2

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp?rev=283869&r1=283868&r2=283869&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp Tue Oct 11 
05:47:06 2016
@@ -238,7 +238,7 @@ void UseDefaultCheck::registerMatchers(M
 isDefinition(),
 anyOf(
 // Default constructor.
-allOf(unless(hasAnyConstructorInitializer(anything())),
+allOf(unless(hasAnyConstructorInitializer(isWritten())),
   parameterCountIs(0)),
 // Copy constructor.
 allOf(isCopyConstructor(),
@@ -296,12 +296,12 @@ void UseDefaultCheck::check(const MatchF
   if (!isCopyConstructorAndCanBeDefaulted(Result.Context, Ctor))
 return;
   SpecialFunctionName = "copy constructor";
-}
-// If there are constructor initializers, they must be removed.
-if (Ctor->getNumCtorInitializers() != 0) {
-  StartLoc = getColonLoc(Result.Context, Ctor);
-  if (!StartLoc.isValid())
-return;
+  // If there are constructor initializers, they must be removed.
+  if (Ctor->getNumCtorInitializers() != 0) {
+StartLoc = getColonLoc(Result.Context, Ctor);
+if (!StartLoc.isValid())
+  return;
+  }
 }
   } else if (isa(SpecialFunctionDecl)) {
 SpecialFunctionName = "destructor";

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp?rev=283869&r1=283868&r2=283869&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp Tue Oct 
11 05:47:06 2016
@@ -43,6 +43,24 @@ public:
   int Field;
 };
 
+// Default member initializer
+class DMI {
+public:
+  DMI() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: DMI() = default;
+  int Field = 5;
+};
+
+// Class member
+class CM {
+public:
+  CM() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: CM() = default;
+  OL o;
+};
+
 // Private constructor/destructor.
 class Priv {
   Priv() {}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24444: [clang-tidy] modernize-use-default default constructor bugfix

2016-10-11 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL283869: [clang-tidy] modernize-use-default default 
constructor bugfix (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D2?vs=70966&id=74232#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D2

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
@@ -43,6 +43,24 @@
   int Field;
 };
 
+// Default member initializer
+class DMI {
+public:
+  DMI() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: DMI() = default;
+  int Field = 5;
+};
+
+// Class member
+class CM {
+public:
+  CM() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: CM() = default;
+  OL o;
+};
+
 // Private constructor/destructor.
 class Priv {
   Priv() {}
Index: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
@@ -238,7 +238,7 @@
 isDefinition(),
 anyOf(
 // Default constructor.
-allOf(unless(hasAnyConstructorInitializer(anything())),
+allOf(unless(hasAnyConstructorInitializer(isWritten())),
   parameterCountIs(0)),
 // Copy constructor.
 allOf(isCopyConstructor(),
@@ -296,12 +296,12 @@
   if (!isCopyConstructorAndCanBeDefaulted(Result.Context, Ctor))
 return;
   SpecialFunctionName = "copy constructor";
-}
-// If there are constructor initializers, they must be removed.
-if (Ctor->getNumCtorInitializers() != 0) {
-  StartLoc = getColonLoc(Result.Context, Ctor);
-  if (!StartLoc.isValid())
-return;
+  // If there are constructor initializers, they must be removed.
+  if (Ctor->getNumCtorInitializers() != 0) {
+StartLoc = getColonLoc(Result.Context, Ctor);
+if (!StartLoc.isValid())
+  return;
+  }
 }
   } else if (isa(SpecialFunctionDecl)) {
 SpecialFunctionName = "destructor";


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
@@ -43,6 +43,24 @@
   int Field;
 };
 
+// Default member initializer
+class DMI {
+public:
+  DMI() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: DMI() = default;
+  int Field = 5;
+};
+
+// Class member
+class CM {
+public:
+  CM() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: CM() = default;
+  OL o;
+};
+
 // Private constructor/destructor.
 class Priv {
   Priv() {}
Index: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
@@ -238,7 +238,7 @@
 isDefinition(),
 anyOf(
 // Default constructor.
-allOf(unless(hasAnyConstructorInitializer(anything())),
+allOf(unless(hasAnyConstructorInitializer(isWritten())),
   parameterCountIs(0)),
 // Copy constructor.
 allOf(isCopyConstructor(),
@@ -296,12 +296,12 @@
   if (!isCopyConstructorAndCanBeDefaulted(Result.Context, Ctor))
 return;
   SpecialFunctionName = "copy constructor";
-}
-// If there are constructor initializers, they must be removed.
-if (Ctor->getNumCtorInitializers() != 0) {
-  StartLoc = getColonLoc(Result.Context, Ctor);
-  if (!StartLoc.isValid())
-return;
+  // If there are constructor initializers, they must be removed.
+  if (Ctor->getNumCtorInitializers() != 0) {
+StartLoc = getColonLoc(Result.Context, Ctor);
+if (!StartLoc.isValid())
+  return;
+  }
 }
   } else if (isa(SpecialFunctionDecl)) {
 SpecialFunctionName = "destructor";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r283873 - [clang-tidy] readability-avoid-const-params-in-decls template instantiation bugfix

2016-10-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Oct 11 07:02:16 2016
New Revision: 283873

URL: http://llvm.org/viewvc/llvm-project?rev=283873&view=rev
Log:
[clang-tidy] readability-avoid-const-params-in-decls template instantiation 
bugfix

Summary: Bugfix for 30398.  Don't warn for template instantiations

Reviewers: aaron.ballman, hokein, alexfh

Subscribers: omtcyfz, cfe-commits

Differential Revision: https://reviews.llvm.org/D24652

Modified:
clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp?rev=283873&r1=283872&r2=283873&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp 
Tue Oct 11 07:02:16 2016
@@ -36,7 +36,12 @@ void AvoidConstParamsInDecls::registerMa
   functionDecl(unless(isDefinition()),
// Lambdas are always their own definition, but they
// generate a non-definition FunctionDecl too. Ignore those.
-   unless(cxxMethodDecl(ofClass(cxxRecordDecl(isLambda(),
+   // Class template instantiations have a non-definition
+   // CXXMethodDecl for methods that aren't used in this
+   // translation unit. Ignore those, as the template will have
+   // already been checked.
+   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(
+   isLambda(), 
ast_matchers::isTemplateInstantiation()),
has(typeLoc(forEach(ConstParamDecl
   .bind("func"),
   this);

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp?rev=283873&r1=283872&r2=283873&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
 Tue Oct 11 07:02:16 2016
@@ -53,6 +53,12 @@ void F12(const bool b = true);
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
 // CHECK-FIXES: void F12(bool b = true);
 
+template
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13();
+
 struct Foo {
   Foo(const int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
@@ -63,6 +69,18 @@ struct Foo {
   // CHECK-FIXES: void operator()(int i);
 };
 
+template 
+struct FooT {
+  FooT(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+  // CHECK-FIXES: FooT(int i);
+
+  void operator()(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(int i);
+};
+FooT f(1);
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -72,6 +90,25 @@ void NF5(const int) {}
 void NF6(const int *const) {}
 void NF7(int, const int) {}
 void NF8(const int, const int) {}
+template 
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+  Bar(const int i) {}
+
+  void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template 
+struct BarT {
+  BarT(const int i) {}
+
+  void operator()(const int i) {}
+};
+BarT b(1);
 
 // Do not match on other stuff
 void NF(const alias_type& i);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24652: [clang-tidy] readability-avoid-const-params-in-decls template instantiation bugfix

2016-10-11 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL283873: [clang-tidy] readability-avoid-const-params-in-decls 
template instantiation… (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D24652?vs=72476&id=74242#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24652

Files:
  clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp


Index: 
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
@@ -53,6 +53,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
 // CHECK-FIXES: void F12(bool b = true);
 
+template
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13();
+
 struct Foo {
   Foo(const int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
@@ -63,6 +69,18 @@
   // CHECK-FIXES: void operator()(int i);
 };
 
+template 
+struct FooT {
+  FooT(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+  // CHECK-FIXES: FooT(int i);
+
+  void operator()(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(int i);
+};
+FooT f(1);
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -72,6 +90,25 @@
 void NF6(const int *const) {}
 void NF7(int, const int) {}
 void NF8(const int, const int) {}
+template 
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+  Bar(const int i) {}
+
+  void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template 
+struct BarT {
+  BarT(const int i) {}
+
+  void operator()(const int i) {}
+};
+BarT b(1);
 
 // Do not match on other stuff
 void NF(const alias_type& i);
Index: 
clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -36,7 +36,12 @@
   functionDecl(unless(isDefinition()),
// Lambdas are always their own definition, but they
// generate a non-definition FunctionDecl too. Ignore those.
-   unless(cxxMethodDecl(ofClass(cxxRecordDecl(isLambda(),
+   // Class template instantiations have a non-definition
+   // CXXMethodDecl for methods that aren't used in this
+   // translation unit. Ignore those, as the template will have
+   // already been checked.
+   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(
+   isLambda(), 
ast_matchers::isTemplateInstantiation()),
has(typeLoc(forEach(ConstParamDecl
   .bind("func"),
   this);


Index: clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
@@ -53,6 +53,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
 // CHECK-FIXES: void F12(bool b = true);
 
+template
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13();
+
 struct Foo {
   Foo(const int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
@@ -63,6 +69,18 @@
   // CHECK-FIXES: void operator()(int i);
 };
 
+template 
+struct FooT {
+  FooT(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+  // CHECK-FIXES: FooT(int i);
+
+  void operator()(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(int i);
+};
+FooT f(1);
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -72,6 +90,25 @@
 void NF6(const int *const) {}
 void NF7(int, const int) {}
 void NF8(const int, const int) {}
+template 
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+  Bar(const int i) {}
+
+  void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template 
+struct BarT {
+  BarT(const int i) {}
+
+  void 

[PATCH] D25238: [clang-tidy] Ignore empty members and bases in cppcoreguidelines-pro-type-member-init

2016-10-11 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL283886: [clang-tidy] Ignore empty members and bases in 
cppcoreguidelines-pro-type… (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D25238?vs=74125&id=74256#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25238

Files:
  
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp


Index: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -317,6 +317,28 @@
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) 
{
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor) {
@@ -330,7 +352,8 @@
   forEachField(ClassDecl, ClassDecl.fields(), false, [&](const FieldDecl *F) {
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
-Context))
+Context) &&
+!isEmpty(Context, F->getType()))
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())
Index: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -423,3 +423,30 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: G
+
+struct NegativeEmpty {
+};
+
+static void NegativeEmptyVar() {
+  NegativeEmpty e;
+  (void)e;
+}
+
+struct NegativeEmptyMember {
+  NegativeEmptyMember() {}
+  NegativeEmpty e;
+};
+
+struct NegativeEmptyBase : NegativeEmpty {
+  NegativeEmptyBase() {}
+};
+
+struct NegativeEmptyArrayMember {
+  NegativeEmptyArrayMember() {}
+  char e[0];
+};
+
+struct NegativeIncompleteArrayMember {
+  NegativeIncompleteArrayMember() {}
+  char e[];
+};


Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -317,6 +317,28 @@
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) {
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor) {
@@ -330,7 +352,8 @@
   forEachField(ClassDecl, ClassDecl.fields(), false, [&](const FieldDecl *F) {
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
-Context))
+Context) &&
+!isEmpty(Context, F->getType()))
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())
Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===

[clang-tools-extra] r283886 - [clang-tidy] Ignore empty members and bases in cppcoreguidelines-pro-type-member-init

2016-10-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Oct 11 09:49:24 2016
New Revision: 283886

URL: http://llvm.org/viewvc/llvm-project?rev=283886&view=rev
Log:
[clang-tidy] Ignore empty members and bases in 
cppcoreguidelines-pro-type-member-init

Summary: Empty/incomplete variables/members/bases don't need to be initialized

Reviewers: mgehre, aaron.ballman, alexfh

Subscribers: nemanjai, cfe-commits

Differential Revision: https://reviews.llvm.org/D25238

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=283886&r1=283885&r2=283886&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
Tue Oct 11 09:49:24 2016
@@ -317,6 +317,28 @@ void ProTypeMemberInitCheck::storeOption
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
 }
 
+// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
+static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) 
{
+  if (T->isIncompleteArrayType())
+return true;
+
+  while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
+if (!ArrayT->getSize())
+  return true;
+
+T = ArrayT->getElementType();
+  }
+
+  return false;
+}
+
+static bool isEmpty(ASTContext &Context, const QualType &Type) {
+  if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
+return ClassDecl->isEmpty();
+  }
+  return isIncompleteOrZeroLengthArrayType(Context, Type);
+}
+
 void ProTypeMemberInitCheck::checkMissingMemberInitializer(
 ASTContext &Context, const CXXRecordDecl &ClassDecl,
 const CXXConstructorDecl *Ctor) {
@@ -330,7 +352,8 @@ void ProTypeMemberInitCheck::checkMissin
   forEachField(ClassDecl, ClassDecl.fields(), false, [&](const FieldDecl *F) {
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
-Context))
+Context) &&
+!isEmpty(Context, F->getType()))
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp?rev=283886&r1=283885&r2=283886&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
 Tue Oct 11 09:49:24 2016
@@ -423,3 +423,30 @@ UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUA
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: G
+
+struct NegativeEmpty {
+};
+
+static void NegativeEmptyVar() {
+  NegativeEmpty e;
+  (void)e;
+}
+
+struct NegativeEmptyMember {
+  NegativeEmptyMember() {}
+  NegativeEmpty e;
+};
+
+struct NegativeEmptyBase : NegativeEmpty {
+  NegativeEmptyBase() {}
+};
+
+struct NegativeEmptyArrayMember {
+  NegativeEmptyArrayMember() {}
+  char e[0];
+};
+
+struct NegativeIncompleteArrayMember {
+  NegativeIncompleteArrayMember() {}
+  char e[];
+};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24888: [clang-tidy] Use [[clang::suppress]] with cppcoreguidelines-pro-type-reinterpret-cast

2016-10-11 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/cppcoreguidelines/ProTypeReinterpretCastCheck.cpp:25
 
-  Finder->addMatcher(cxxReinterpretCastExpr().bind("cast"), this);
+  std::vector Rules{"type", "type.1", 
"cppcoreguidelines-pro-type-reinterpret-cast"};
+  
Finder->addMatcher(cxxReinterpretCastExpr(unless(isSuppressed(Rules))).bind("cast"),
 this);

aaron.ballman wrote:
> mgehre wrote:
> > aaron.ballman wrote:
> > > Hmm, it seems like this is boilerplate we are going to want for every 
> > > rule, and that it's pretty easy to not get this right (for instance, if 
> > > you change the way the check is spelled, you have to remember to update 
> > > this as well). Could this actually be handled more transparently, by 
> > > gathering this information when the check is registered and exposing it 
> > > to the check?
> > > 
> > > The checks would still need to use `unless(isSuppressed(Rules))` in some 
> > > form, but I am thinking that it would be more convenient if we could do: 
> > > `Finder->addMatcher(cxxReinterpretCastExpr(unlessSuppressed(*this)).bind("cast"),
> > >  this);`
> > I see multiple ways on how to integrate that into clang-tidy:
> > 1) Add something like you proposed to each matcher of each check
> > 2) Change (or add overload of)
> > ```
> >  DiagnosticBuilder diag(SourceLocation Loc, StringRef Description,
> >  DiagnosticIDs::Level Level = 
> > DiagnosticIDs::Warning);
> > ```
> > to add a AST node as parameter and make the SourceLocation optional. Most 
> > checks anyhow
> > call this like diag(E->getLoc(), ""), and then they would do diag(E, 
> > "...").
> > Diag then would check from the that AST node upwards to see if it finds a 
> > matching [[suppress]] attribute
> > 
> > 3) Change the RecursiveASTVistor that drives the AST Matches to prune 
> > certain matchers from the list of to-be-evaluated matchers
> > for all AST subtrees that are below a certain [[suppress]] attribute. (This 
> > is based on how I image that the AST matchers work)
> Ideally, I would like to see this attribute used to suppress Clang 
> diagnostics as well, however. So while I think Option 2 is better suited to 
> that future direction, it's still not ideal because all instances of diag() 
> need to be updated to take advantage. Options 1 and 3 are basically limited 
> to clang-tidy use.
> 
> I wonder if there's a way to modify the diagnostic builder to transparently 
> handle this without requiring modifying all of the call sites?
clang-tidy reports how many warnings were suppressed by NOLINT comments.
I'd expect the number of warnings suppressed by [[clang::suppress]] to be 
included in the count.
Handling suppressions in the matchers or visitors would prevent this.


https://reviews.llvm.org/D24888



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25406: Fix doubled whitespace in modernize-use-auto fixit

2016-10-11 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:378
+  Lexer::getLocForEndOfToken(Range.getEnd(), 0, SM, 
Context->getLangOpts());
+  bool Whitespace = isWhitespace(*FullSourceLoc(Next, SM).getCharacterData());
+

aaron.ballman wrote:
> malcolm.parsons wrote:
> > aaron.ballman wrote:
> > > Oye, this is deceptively expensive because you now have to go back to the 
> > > actual source file for this information. That source file may live on a 
> > > network share somewhere, for instance.
> > > 
> > > Can you use `Token::hasLeadingSpace()` instead?
> > > 
> > > Also, doesn't this still need to care about the `RemoveStars` option?
> > Where would I get a Token from?
> Hrm, might not be as trivial as I was hoping (I thought we had a way to go 
> from a `SourceLocation` back to a `Token`, but I'm not seeing one off-hand). 
> Regardless, I worry about the expense of going all the way back to the source 
> for this.
> 
> @alexfh -- should this functionality be a part of a more general "we've made 
> a fixit, now make it not look ugly?" pass? At least then, if we go back to 
> the source, we can do it in a more controlled manner and hopefully get some 
> performance back from that.
`LineIsMarkedWithNOLINT` is going to read the source anyway, so I don't see any 
additional expense.


https://reviews.llvm.org/D25406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25406: Fix doubled whitespace in modernize-use-auto fixit

2016-10-12 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:378
+  Lexer::getLocForEndOfToken(Range.getEnd(), 0, SM, 
Context->getLangOpts());
+  bool Whitespace = isWhitespace(*FullSourceLoc(Next, SM).getCharacterData());
+

aaron.ballman wrote:
> malcolm.parsons wrote:
> > aaron.ballman wrote:
> > > malcolm.parsons wrote:
> > > > aaron.ballman wrote:
> > > > > Oye, this is deceptively expensive because you now have to go back to 
> > > > > the actual source file for this information. That source file may 
> > > > > live on a network share somewhere, for instance.
> > > > > 
> > > > > Can you use `Token::hasLeadingSpace()` instead?
> > > > > 
> > > > > Also, doesn't this still need to care about the `RemoveStars` option?
> > > > Where would I get a Token from?
> > > Hrm, might not be as trivial as I was hoping (I thought we had a way to 
> > > go from a `SourceLocation` back to a `Token`, but I'm not seeing one 
> > > off-hand). Regardless, I worry about the expense of going all the way 
> > > back to the source for this.
> > > 
> > > @alexfh -- should this functionality be a part of a more general "we've 
> > > made a fixit, now make it not look ugly?" pass? At least then, if we go 
> > > back to the source, we can do it in a more controlled manner and 
> > > hopefully get some performance back from that.
> > `LineIsMarkedWithNOLINT` is going to read the source anyway, so I don't see 
> > any additional expense.
> The additional expense comes from many checks needing similar functionality 
> -- generally, fixit replacements are going to require formatting 
> modifications of some sort. It's better to handle all of those in the same 
> place and transparently rather than have every check with a fixit manually 
> handle formatting. Additionally, this means we can go back to the source as 
> infrequently as possible.
I ran strace -c on clang-tidy on several real world source files that 
modernize-use-auto warns about before and after this change and the counts for 
read, write, stat, open, close, openat and fstat syscalls were all unchanged.
The expense is exactly zero.
It will still be zero when multiplied by many checks.
There is no performance issue here.
Do you have any other issues with this change?


https://reviews.llvm.org/D25406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25316: [clang-tidy] Enhance modernize-use-auto to casts

2016-10-13 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74476.
malcolm.parsons added a comment.

Combine matchers


https://reviews.llvm.org/D25316

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -15,6 +15,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use auto when initializing with new
   // CHECK-FIXES: static auto *a_static = new MyType();
 
+  long long *ll = new long long();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
+  // CHECK-FIXES: auto *ll = new long long();
+
   MyType *derived = new MyDerivedType();
 
   void *vd = new MyType();
Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -0,0 +1,120 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
+// RUN:   -std=c++11 -I %S/Inputs/modernize-use-auto
+
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {};
+
+struct C {};
+
+void f_static_cast() {
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = static_cast(l);
+
+  const int i2 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto i2 = static_cast(l);
+
+  long long ll = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ll = static_cast(l);
+  unsigned long long ull = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ull = static_cast(l);
+  unsigned int ui = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ui = static_cast(l);
+  long double ld = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto ld = static_cast(l);
+
+  A *a = new B();
+  B *b1 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = static_cast(a);
+
+  B *const b2 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *const b2 = static_cast(a);
+
+  const B *b3 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b3 = static_cast(a);
+
+  B &b4 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = static_cast(*a);
+
+  const B &b5 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b5 = static_cast(*a);
+
+  B &b6 = static_cast(*a), &b7 = static_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b6 = static_cast(*a), &b7 = static_cast(*a);
+
+  // Don't warn when non-cast involved
+  long double cast = static_cast(l), noncast = 5;
+
+  // Don't warn when auto is already being used.
+  auto i3 = static_cast(l);
+  auto *b8 = static_cast(a);
+  auto &b9 = static_cast(*a);
+}
+
+void f_dynamic_cast() {
+  A *a = new B();
+  B *b1 = dynamic_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = dynamic_cast(a);
+
+  B &b2 = dynamic_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = dynamic_cast(*a);
+}
+
+void f_reinterpret_cast() {
+  auto *a = new A();
+  C *c1 = reinterpret_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *c1 = reinterpret_cast(a);
+
+  C &c2 = reinterpret_cast(*a);
+  // CHECK-MESSAGES: :[[@

[PATCH] D25024: [clang-tidy] Add check for detecting declarations with multiple names

2016-10-13 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: test/clang-tidy/cppcoreguidelines-one-name-per-declaration.cpp:8
+  {
+int x = 42, y = 43;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Do not declare multiple names 
per declaration [cppcoreguidelines-one-name-per-declaration]

omtcyfz wrote:
> malcolm.parsons wrote:
> > The guideline says "Flag non-function arguments with multiple declarators 
> > involving declarator operators (e.g., int* p, q;)".
> > 
> > There are no declarator operators in this test, so there should be no 
> > warning.
> The guideline says
> 
> > Reason: One-declaration-per line increases readability and avoids mistakes 
> > related to the C/C++ grammar. It also leaves room for a more descriptive 
> > end-of-line comment.
> 
> > Exception: a function declaration can contain several function argument 
> > declarations.
> 
> I'm not sure why what you copied is written in "Enforcement" section, but I 
> do not think that is how it should be handled. I am concerned not only about 
> that specific case and I see no reason to cut off cases already presented in 
> this test.
"mistakes related to the C/C++ grammar" only occur when declarator operators 
are involved. e.g. in `int* p, q` a reader might incorrectly think that q was a 
pointer.

I see reasons not to warn about cases like
`for (auto i = c.begin(), e = someExpensiveFn(); i != e; i++)`
`for (int i = 0, j = someExpensiveFn(); i < j; i++);`
because the alternatives increase variable scope, or for
`int x = 42, y = 43;`
because it's not difficult to read.

As we disagree on this, can it be made configurable?


https://reviews.llvm.org/D25024



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-10-15 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 74769.
malcolm.parsons added a comment.

Use ignoringImplicit


https://reviews.llvm.org/D24339

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tidy/readability/RedundantMemberInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-member-init.rst
  test/clang-tidy/readability-redundant-member-init.cpp

Index: test/clang-tidy/readability-redundant-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-member-init.cpp
@@ -0,0 +1,181 @@
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+
+struct S {
+  S() = default;
+  S(int i) : i(i) {}
+  int i = 1;
+};
+
+struct T {
+  T(int i = 1) : i(i) {}
+  int i;
+};
+
+struct U {
+  int i;
+};
+
+union V {
+  int i;
+  double f;
+};
+
+// Initializer calls default constructor
+struct F1 {
+  F1() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-FIXES: F1()  {}
+  S f;
+};
+
+// Initializer calls default constructor with default argument
+struct F2 {
+  F2() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-FIXES: F2()  {}
+  T f;
+};
+
+// Multiple redundant initializers for same constructor
+struct F3 {
+  F3() : f(), g(1), h() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: initializer for member 'h' is redundant
+  // CHECK-FIXES: F3() :  g(1) {}
+  S f, g, h;
+};
+
+// Templated class independent type
+template 
+struct F4 {
+  F4() : f() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+  // CHECK-FIXES: F4()  {}
+  S f;
+};
+F4 f4i;
+F4 f4s;
+
+// Base class
+struct F5 : S {
+  F5() : S() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant
+  // CHECK-FIXES: F5()  {}
+};
+
+// Constructor call requires cleanup
+struct Cleanup {
+  ~Cleanup() {}
+};
+
+struct UsesCleanup {
+  UsesCleanup(const Cleanup &c = Cleanup()) {}
+};
+
+struct F6 {
+  F6() : uc() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'uc' is redundant
+  // CHECK-FIXES: F6()  {}
+  UsesCleanup uc;
+};
+
+// Multiple inheritance
+struct F7 : S, T {
+  F7() : S(), T() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant
+  // CHECK-MESSAGES: :[[@LINE-2]]:15: warning: initializer for base class 'T' is redundant
+  // CHECK-FIXES: F7()  {}
+};
+
+// Initializer not written
+struct NF1 {
+  NF1() {}
+  S f;
+};
+
+// Initializer doesn't call default constructor
+struct NF2 {
+  NF2() : f(1) {}
+  S f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF3 {
+  NF3() : f(1) {}
+  T f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF4 {
+  NF4() : f(2) {}
+  T f;
+};
+
+// Initializer is zero-initialization
+struct NF5 {
+  NF5() : i() {}
+  int i;
+};
+
+// Initializer is direct-initialization
+struct NF6 {
+  NF6() : i(1) {}
+  int i;
+};
+
+// Initializer is aggregate initialization of struct
+struct NF7 {
+  NF7() : f{} {}
+  U f;
+};
+
+// Initializer is zero-initialization of struct
+struct NF7b {
+  NF7b() : f() {}
+  U f;
+};
+
+// Initializer is aggregate initialization of array
+struct NF8 {
+  NF8() : f{} {}
+  int f[2];
+};
+
+struct NF9 {
+  NF9() : f{} {}
+  S f[2];
+};
+
+// Initializing member of union
+union NF10 {
+  NF10() : s() {}
+  int i;
+  S s;
+};
+
+// Templated class dependent type
+template 
+struct NF11 {
+  NF11() : f() {}
+  V f;
+};
+NF11 nf11i;
+NF11 nf11s;
+
+// Delegating constructor
+class NF12 {
+  NF12() = default;
+  NF12(int) : NF12() {}
+};
+
+// Const member
+struct NF13 {
+  NF13() : f() {}
+  const S f;
+};
+
+// Union member
+struct NF14 {
+  NF14() : f() {}
+  V f;
+};
Index: docs/clang-tidy/checks/readability-redundant-member-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-member-init.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - readability-redundant-member-init
+
+readability-redundant-member-init
+=
+
+Finds member initializations that are unnecessary because the same default
+constructor would be called if they were not present.
+
+Example:
+
+.. code-block:: c++
+
+  // Explicitly initializing the member s is unnecessary.
+  class Foo {
+  public:
+Foo() : s() {}
+
+  private:
+std::string s;
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rs

[PATCH] D25642: [clang-tidy] Use ignoreImplicit in cert-err58-cpp check

2016-10-15 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added a reviewer: aaron.ballman.
malcolm.parsons added a subscriber: cfe-commits.

Fix a false negative in cert-err58-cpp check when calling a constructor
creates objects that require cleanup.


https://reviews.llvm.org/D25642

Files:
  clang-tidy/cert/StaticObjectExceptionCheck.cpp
  test/clang-tidy/cert-static-object-exception.cpp

Index: test/clang-tidy/cert-static-object-exception.cpp
===
--- test/clang-tidy/cert-static-object-exception.cpp
+++ test/clang-tidy/cert-static-object-exception.cpp
@@ -16,6 +16,15 @@
   explicit V(const char *) {} // Can throw
 };
 
+struct Cleanup
+{
+  ~Cleanup() {}
+};
+
+struct W {
+  W(Cleanup c = {}) noexcept(false);
+};
+
 
 S s;
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
@@ -27,30 +36,38 @@
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
 
-void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
+void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
   S s2; // ok
   T t2; // ok
   U u2; // ok
   V v2("v"); // ok
+  W w2; // ok
 
   thread_local S s3; // ok
   thread_local T t3; // ok
   thread_local U u3; // ok
   thread_local V v3("v"); // ok
+  thread_local W w3; // ok
 
   static S s4; // ok
   static T t4; // ok
   static U u4; // ok
   static V v4("v"); // ok
+  static W w4; // ok
 }
 
 namespace {
@@ -64,14 +81,19 @@
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
 };
 
 class Statics {
@@ -85,22 +107,28 @@
   static V v;
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
   // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+  static W w;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+  // CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
   void f(S s, T t, U u, V v) {
 S s2;  // ok
 T t2;  // ok
 U u2;  // ok
 V v2("v"); // ok
+W w2;  // ok
 
 thread_local S s3;  // ok
 thread_local T t3;  // ok
 thread_local U u3;  // ok
 thread_local V v3("v"); // ok
+thread_local W w3;  // ok
 
 static S s4;  // ok
 static T t4;  // ok
 static U u4;  // ok
 static V v4("v"); // ok
+static W w4;  // ok
   }
 };
 
@@ -114,3 +142,6 @@
 V Statics::v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constr

[clang-tools-extra] r284332 - [clang-tidy] Use ignoreImplicit in cert-err58-cpp check

2016-10-16 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Sun Oct 16 04:47:10 2016
New Revision: 284332

URL: http://llvm.org/viewvc/llvm-project?rev=284332&view=rev
Log:
[clang-tidy] Use ignoreImplicit in cert-err58-cpp check

Summary:
Fix a false negative in cert-err58-cpp check when calling a constructor
creates objects that require cleanup.

Reviewers: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25642

Modified:
clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp?rev=284332&r1=284331&r2=284332&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp Sun 
Oct 16 04:47:10 2016
@@ -27,8 +27,8 @@ void StaticObjectExceptionCheck::registe
   Finder->addMatcher(
   varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
   unless(hasAncestor(functionDecl())),
-  hasInitializer(cxxConstructExpr(hasDeclaration(
-  cxxConstructorDecl(unless(isNoThrow())).bind("ctor")
+  hasInitializer(ignoringImplicit(cxxConstructExpr(hasDeclaration(
+  cxxConstructorDecl(unless(isNoThrow())).bind("ctor"))
   .bind("var"),
   this);
 }

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp?rev=284332&r1=284331&r2=284332&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
Sun Oct 16 04:47:10 2016
@@ -16,6 +16,15 @@ struct V {
   explicit V(const char *) {} // Can throw
 };
 
+struct Cleanup
+{
+  ~Cleanup() {}
+};
+
+struct W {
+  W(Cleanup c = {}) noexcept(false);
+};
+
 
 S s;
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static 
storage duration may throw an exception that cannot be caught [cert-err58-cpp]
@@ -27,6 +36,9 @@ U u;
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static 
storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static 
storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with 
thread_local storage duration may throw an exception that cannot be caught
@@ -35,22 +47,27 @@ thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with 
thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with 
thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with 
thread_local storage duration may throw an exception that cannot be caught
 
-void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
+void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
   S s2; // ok
   T t2; // ok
   U u2; // ok
   V v2("v"); // ok
+  W w2; // ok
 
   thread_local S s3; // ok
   thread_local T t3; // ok
   thread_local U u3; // ok
   thread_local V v3("v"); // ok
+  thread_local W w3; // ok
 
   static S s4; // ok
   static T t4; // ok
   static U u4; // ok
   static V v4("v"); // ok
+  static W w4; // ok
 }
 
 namespace {
@@ -64,6 +81,9 @@ U u;
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static 
storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static 
storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with 
thread_local storage duration may throw an exception that cannot be caught
@@ -72,6 +92,8 @@ thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with 
thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");

[PATCH] D25642: [clang-tidy] Use ignoreImplicit in cert-err58-cpp check

2016-10-16 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284332: [clang-tidy] Use ignoreImplicit in cert-err58-cpp 
check (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D25642?vs=74770&id=74787#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25642

Files:
  clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
@@ -16,6 +16,15 @@
   explicit V(const char *) {} // Can throw
 };
 
+struct Cleanup
+{
+  ~Cleanup() {}
+};
+
+struct W {
+  W(Cleanup c = {}) noexcept(false);
+};
+
 
 S s;
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
@@ -27,30 +36,38 @@
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
 
-void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
+void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
   S s2; // ok
   T t2; // ok
   U u2; // ok
   V v2("v"); // ok
+  W w2; // ok
 
   thread_local S s3; // ok
   thread_local T t3; // ok
   thread_local U u3; // ok
   thread_local V v3("v"); // ok
+  thread_local W w3; // ok
 
   static S s4; // ok
   static T t4; // ok
   static U u4; // ok
   static V v4("v"); // ok
+  static W w4; // ok
 }
 
 namespace {
@@ -64,14 +81,19 @@
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
 };
 
 class Statics {
@@ -85,22 +107,28 @@
   static V v;
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
   // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+  static W w;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+  // CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
   void f(S s, T t, U u, V v) {
 S s2;  // ok
 T t2;  // ok
 U u2;  // ok
 V v2("v"); // ok
+W w2;  // ok
 
 thread_local S s3;  // ok
 thread_local T t3;  // ok
 thread_local U u3;  // ok
 thread_local V v3("v"); // ok
+thread_local W w3;  // ok
 
 static S s4;  // ok
 static T t4;  // ok
 static U u4;  // ok
 static V v4("v"); // ok
+static W w4;  // ok
   }
 };
 
@@ -114,3 +142,6 @@
 V Statics::v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]

[PATCH] D25659: [clang-tidy] Avoid running aliased checks twice

2016-10-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, klimek, alexfh.
malcolm.parsons added a subscriber: cfe-commits.
Herald added a subscriber: nemanjai.

It is easy to configure clang-tidy with both aliased and original
checks enabled.  This causes the check to be appear under both names
in -list-checks and -dump-config, and the check is run twice.

This changeset tells the CheckFactory about aliases so that an alias
is only enabled when the original is not enabled.


https://reviews.llvm.org/D25659

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyModule.cpp
  clang-tidy/ClangTidyModule.h
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/google/GoogleTidyModule.cpp

Index: clang-tidy/google/GoogleTidyModule.cpp
===
--- clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tidy/google/GoogleTidyModule.cpp
@@ -10,10 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../readability/BracesAroundStatementsCheck.h"
-#include "../readability/FunctionSizeCheck.h"
-#include "../readability/NamespaceCommentCheck.h"
-#include "../readability/RedundantSmartptrGetCheck.h"
 #include "AvoidCStyleCastsCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "ExplicitConstructorCheck.h"
@@ -61,19 +57,16 @@
 "google-readability-casting");
 CheckFactories.registerCheck(
 "google-readability-todo");
-CheckFactories
-.registerCheck(
-"google-readability-braces-around-statements");
+CheckFactories.registerAlias("google-readability-braces-around-statements",
+ "readability-braces-around-statements");
 CheckFactories.registerCheck(
 "google-global-names-in-headers");
-CheckFactories.registerCheck(
-"google-readability-function-size");
-CheckFactories
-.registerCheck(
-"google-readability-namespace-comments");
-CheckFactories
-.registerCheck(
-"google-readability-redundant-smartptr-get");
+CheckFactories.registerAlias("google-readability-function-size",
+ "readability-function-size");
+CheckFactories.registerAlias("google-readability-namespace-comments",
+ "llvm-namespace-comment");
+CheckFactories.registerAlias("google-readability-redundant-smartptr-get",
+ "readability-redundant-smartptr-get");
   }
 
   ClangTidyOptions getModuleOptions() override {
Index: clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -10,7 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "InterfacesGlobalInitCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
@@ -33,6 +32,9 @@
 class CppCoreGuidelinesModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerAlias(
+"cppcoreguidelines-c-copy-assignment-signature",
+"misc-unconventional-assign-operator");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck(
@@ -59,8 +61,6 @@
 "cppcoreguidelines-special-member-functions");
 CheckFactories.registerCheck(
 "cppcoreguidelines-slicing");
-CheckFactories.registerCheck(
-"cppcoreguidelines-c-copy-assignment-signature");
   }
 };
 
Index: clang-tidy/cert/CERTTidyModule.cpp
===
--- clang-tidy/cert/CERTTidyModule.cpp
+++ clang-tidy/cert/CERTTidyModule.cpp
@@ -10,12 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../google/UnnamedNamespaceInHeaderCheck.h"
-#include "../misc/MoveConstructorInitCheck.h"
-#include "../misc/NewDeleteOverloadsCheck.h"
-#include "../misc/NonCopyableObjects.h"
-#include "../misc/StaticAssertCheck.h"
-#include "../misc/ThrowByValueCatchByReferenceCheck.h"
 #include "CommandProcessorCheck.h"
 #include "FloatLoopCounter.h"
 #include "SetLongJmpCheck.h"
@@ -35,36 +29,31 @@
 // DCL
 CheckFactories.registerCheck(
 "cert-dcl50-cpp");
-CheckFactories.registerCheck(
-"cert-dcl54-cpp");
-CheckFactories.registerCheck(
-"cert-dcl59-cpp");
+CheckFactories.registerAlias("cert-dcl54-cpp", "misc-new-delete-overloads");
+CheckFactories.registerAlias("cert-dcl59-cpp", "google-build-namespaces");
 // O

[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-17 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a comment.

ping.


https://reviews.llvm.org/D25363



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r319174 - [clang-tidy] Ignore ExprWithCleanups when looking for else-after-throw

2017-11-28 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Nov 28 06:57:47 2017
New Revision: 319174

URL: http://llvm.org/viewvc/llvm-project?rev=319174&view=rev
Log:
[clang-tidy] Ignore ExprWithCleanups when looking for else-after-throw

Summary:
The readability-else-after-return check was not warning about
an else after a throw of an exception that had arguments that needed
to be cleaned up.

Reviewers: aaron.ballman, alexfh, djasper

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, klimek, xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D40505

Modified:
clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp?rev=319174&r1=319173&r2=319174&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp Tue 
Nov 28 06:57:47 2017
@@ -21,7 +21,8 @@ namespace readability {
 void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
   const auto ControlFlowInterruptorMatcher =
   stmt(anyOf(returnStmt().bind("return"), continueStmt().bind("continue"),
- breakStmt().bind("break"), cxxThrowExpr().bind("throw")));
+ breakStmt().bind("break"),
+ expr(ignoringImplicit(cxxThrowExpr().bind("throw");
   Finder->addMatcher(
   compoundStmt(forEach(
   ifStmt(hasThen(stmt(

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp?rev=319174&r1=319173&r2=319174&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp 
Tue Nov 28 06:57:47 2017
@@ -1,5 +1,16 @@
 // RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -std=c++11 
-fexceptions
 
+namespace std {
+struct string {
+  string(const char *);
+  ~string();
+};
+} // namespace std
+
+struct my_exception {
+  my_exception(const std::string &s);
+};
+
 void f(int a) {
   if (a > 0)
 return;
@@ -85,5 +96,12 @@ void foo() {
 // CHECK-FIXES: {{^}}} // comment-9
   x++;
 }
+if (x) {
+  throw my_exception("foo");
+} else { // comment-10
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'throw'
+// CHECK-FIXES: {{^}}} // comment-10
+  x++;
+}
   }
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r320396 - [Sema] Fix crash in unused-lambda-capture warning for VLAs

2017-12-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Mon Dec 11 10:00:36 2017
New Revision: 320396

URL: http://llvm.org/viewvc/llvm-project?rev=320396&view=rev
Log:
[Sema] Fix crash in unused-lambda-capture warning for VLAs

Summary:
Clang was crashing when diagnosing an unused-lambda-capture for a VLA because
From.getVariable() is null for the capture of a VLA bound.
Warning about the VLA bound capture is not helpful, so only warn for the VLA
itself.

Fixes: PR3

Reviewers: aaron.ballman, dim, rsmith

Reviewed By: aaron.ballman, dim

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D41016

Modified:
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=320396&r1=320395&r2=320396&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Mon Dec 11 10:00:36 2017
@@ -560,6 +560,7 @@ public:
 void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
 VarDecl *getVariable() const {
+  assert(isVariableCapture());
   return VarAndNestedAndThis.getPointer();
 }
 

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=320396&r1=320395&r2=320396&view=diff
==
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Mon Dec 11 10:00:36 2017
@@ -1481,6 +1481,9 @@ void Sema::DiagnoseUnusedLambdaCapture(c
   if (CaptureHasSideEffects(From))
 return;
 
+  if (From.isVLATypeCapture())
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";

Modified: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp?rev=320396&r1=320395&r2=320396&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp Mon Dec 11 10:00:36 
2017
@@ -191,3 +191,12 @@ void test_templated() {
 void test_use_template() {
   test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }
+
+namespace pr3 {
+int a;
+void b() {
+  int c[a];
+  auto vla_used = [&c] { return c[0]; };
+  auto vla_unused = [&c] {}; // expected-warning{{lambda capture 'c' is not 
used}}
+}
+} // namespace pr3


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-23 Thread Malcolm Parsons via cfe-commits

pepsiman wrote:

`createReplacementsForHeaders()` is applying a cleanup without checking the 
`Cleanup` flag.
But clang-apply-replacements always sets `Cleanup` to `true` anyway.
The change looks good to me, but it might be working around a bug elsewhere.

https://github.com/llvm/llvm-project/pull/70801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r309668 - [clang-tidy] Handle anonymous structs/unions in member init checks.

2017-08-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Aug  1 02:54:05 2017
New Revision: 309668

URL: http://llvm.org/viewvc/llvm-project?rev=309668&view=rev
Log:
[clang-tidy] Handle anonymous structs/unions in member init checks.

Use getAnyMember() instead of getMember() to avoid crash on anonymous
structs/unions.
Don't warn about initializing members of an anonymous union.

Fixes PR32966.

Reviewed by alexfh.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=309668&r1=309667&r2=309668&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Tue Aug  1 02:54:05 2017
@@ -166,21 +166,22 @@ void UseDefaultMemberInitCheck::register
   cxxConstructorDecl(
   isDefaultConstructor(), unless(isInstantiated()),
   forEachConstructorInitializer(
-  allOf(forField(unless(anyOf(isBitField(),
-  hasInClassInitializer(anything(),
-cxxCtorInitializer(isWritten(),
-   withInitializer(ignoringImplicit(Init)))
-.bind("default",
+  cxxCtorInitializer(
+  forField(unless(anyOf(isBitField(),
+hasInClassInitializer(anything()),
+hasParent(recordDecl(isUnion()),
+  isWritten(), withInitializer(ignoringImplicit(Init)))
+  .bind("default"))),
   this);
 
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(ast_matchers::isTemplateInstantiation()),
   forEachConstructorInitializer(
-  allOf(forField(hasInClassInitializer(anything())),
-cxxCtorInitializer(isWritten(),
-   withInitializer(ignoringImplicit(Init)))
-.bind("existing",
+  cxxCtorInitializer(forField(hasInClassInitializer(anything())),
+ isWritten(),
+ withInitializer(ignoringImplicit(Init)))
+  .bind("existing"))),
   this);
 }
 
@@ -197,7 +198,7 @@ void UseDefaultMemberInitCheck::check(co
 
 void UseDefaultMemberInitCheck::checkDefaultInit(
 const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) {
-  const FieldDecl *Field = Init->getMember();
+  const FieldDecl *Field = Init->getAnyMember();
 
   SourceLocation StartLoc = Field->getLocStart();
   if (StartLoc.isMacroID() && IgnoreMacros)

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp?rev=309668&r1=309667&r2=309668&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp 
Tue Aug  1 02:54:05 2017
@@ -39,7 +39,8 @@ void RedundantMemberInitCheck::registerM
   forEachConstructorInitializer(
   cxxCtorInitializer(isWritten(),
  withInitializer(ignoringImplicit(Construct)),
- unless(forField(hasType(isConstQualified()
+ unless(forField(hasType(isConstQualified(,
+ 
unless(forField(hasParent(recordDecl(isUnion())
   .bind("init"))),
   this);
 }
@@ -52,7 +53,7 @@ void RedundantMemberInitCheck::check(con
   Construct->getArg(0)->isDefaultArgument()) {
 if (Init->isAnyMemberInitializer()) {
   diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << Init->getMember()
+  << Init->getAnyMember()
   << FixItHint::CreateRemoval(Init->getSourceRange());
 } else {
   diag(Init->getSourceLocation(),

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=309668&r1=309667&r2=309668&view=diff
==
--- 
clang-too

r309667 - [ASTMatchers] Allow forField to match indirect fields.

2017-08-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Aug  1 02:53:55 2017
New Revision: 309667

URL: http://llvm.org/viewvc/llvm-project?rev=309667&view=rev
Log:
[ASTMatchers] Allow forField to match indirect fields.

This is needed for PR32966.

Reviewed by alexfh.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=309667&r1=309666&r2=309667&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Aug  1 02:53:55 2017
@@ -3237,7 +3237,7 @@ AST_MATCHER_P(CXXConstructorDecl, hasAny
 /// with forField matching foo_
 AST_MATCHER_P(CXXCtorInitializer, forField,
   internal::Matcher, InnerMatcher) {
-  const FieldDecl *NodeAsDecl = Node.getMember();
+  const FieldDecl *NodeAsDecl = Node.getAnyMember();
   return (NodeAsDecl != nullptr &&
   InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
 }

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=309667&r1=309666&r2=309667&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Tue Aug  1 
02:53:55 2017
@@ -785,14 +785,18 @@ TEST(HasAnyConstructorInitializer, ForFi
   static const char Code[] =
 "class Baz { };"
   "class Foo {"
-  "  Foo() : foo_() { }"
+  "  Foo() : foo_(), bar_() { }"
   "  Baz foo_;"
-  "  Baz bar_;"
+  "  struct {"
+  "Baz bar_;"
+  "  };"
   "};";
   EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
 forField(hasType(recordDecl(hasName("Baz";
   EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
 forField(hasName("foo_"));
+  EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
+forField(hasName("bar_"));
   EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
 forField(hasType(recordDecl(hasName("Bar";
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 45924eb - [clang-tidy] Ignore implicit casts in modernize-use-default-member-init

2020-01-14 Thread Malcolm Parsons via cfe-commits

Author: Malcolm Parsons
Date: 2020-01-14T10:05:12Z
New Revision: 45924eb4671692b3fa9fd52fe39c81ec0647a848

URL: 
https://github.com/llvm/llvm-project/commit/45924eb4671692b3fa9fd52fe39c81ec0647a848
DIFF: 
https://github.com/llvm/llvm-project/commit/45924eb4671692b3fa9fd52fe39c81ec0647a848.diff

LOG: [clang-tidy] Ignore implicit casts in modernize-use-default-member-init

Summary:
Initialising a pointer from nullptr involves an implicit cast.
Ignore it after getting initialiser from InitListExpr.

Fixes: PR0

Reviewers: aaron.ballman, alexfh, JonasToth

Reviewed By: JonasToth

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72630

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index 1e59acb1ff17..e99a90ffba57 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -137,7 +137,7 @@ static const Expr *ignoreUnaryPlus(const Expr *E) {
 static const Expr *getInitializer(const Expr *E) {
   auto *InitList = dyn_cast(E);
   if (InitList && InitList->getNumInits() == 1)
-return InitList->getInit(0);
+return InitList->getInit(0)->IgnoreParenImpCasts();
   return E;
 }
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
index 5af9855835ca..0dffeea1c9b7 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
@@ -291,7 +291,7 @@ struct ExistingInt {
   int e1{};
   int e2 = 0;
   int e3 = {5};
-  int e4 = 5;
+  int e4{5};
   int e5 = -5;
   int e6 = +5;
 };
@@ -315,7 +315,7 @@ struct ExistingDouble {
   double e1{};
   double e2 = 0.0;
   double e3 = 5.0;
-  double e4 = -5.0;
+  double e4{-5.0};
   double e5 = +5.0;
 };
 
@@ -333,7 +333,7 @@ struct ExistingBool {
   // CHECK-FIXES: ExistingBool(long) : e1(true), e2(true) {}
   bool e1{};
   bool e2 = false;
-  bool e3 = true;
+  bool e3{true};
 };
 
 struct ExistingEnum {
@@ -365,7 +365,7 @@ struct ExistingPointer {
   // CHECK-FIXES: ExistingPointer(long) :  e4(&e2) {}
   int *e1{};
   int *e2 = 0;
-  int *e3 = nullptr;
+  int *e3{nullptr};
   int **e4 = &e1;
 };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9738c75 - [clang-tidy] Match InitListExpr in modernize-use-default-member-init

2020-01-14 Thread Malcolm Parsons via cfe-commits

Author: Malcolm Parsons
Date: 2020-01-14T15:19:37Z
New Revision: 9738c757bd9bc2fdca935f2b4e356f1d5e5f3682

URL: 
https://github.com/llvm/llvm-project/commit/9738c757bd9bc2fdca935f2b4e356f1d5e5f3682
DIFF: 
https://github.com/llvm/llvm-project/commit/9738c757bd9bc2fdca935f2b4e356f1d5e5f3682.diff

LOG: [clang-tidy] Match InitListExpr in modernize-use-default-member-init

Summary:
modernize-use-default-member-init wasn't warning about redundant initialisers
when the initialiser was an InitListExpr.  Add initListExpr to the matcher.

Fixes: PR44439

Reviewers: aaron.ballman, alexfh, JonasToth

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72691

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index e99a90ffba57..5d62e5446f6a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -201,7 +201,7 @@ void 
UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
 unaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-")),
   hasUnaryOperand(floatLiteral())),
 cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
-declRefExpr(to(enumConstantDecl(;
+initListExpr(), declRefExpr(to(enumConstantDecl(;
 
   Finder->addMatcher(
   cxxConstructorDecl(

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
index 0dffeea1c9b7..196eec91b8e8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
@@ -247,24 +247,24 @@ struct NegativeDefaultArg
 };
 
 struct ExistingChar {
-  ExistingChar(short) : e1(), e2(), e3(), e4() {}
+  ExistingChar(short) : e1(), e2{}, e3(), e4() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is 
redundant [modernize-use-default-member-init]
   // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is 
redundant
   // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is 
redundant
   // CHECK-FIXES: ExistingChar(short) :  e4() {}
-  ExistingChar(int) : e1(0), e2(0), e3(0), e4(0) {}
+  ExistingChar(int) : e1(0), e2{0}, e3(0), e4(0) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is 
redundant
   // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is 
redundant
   // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is 
redundant
   // CHECK-FIXES: ExistingChar(int) :  e4(0) {}
-  ExistingChar(long) : e1('\0'), e2('\0'), e3('\0'), e4('\0') {}
+  ExistingChar(long) : e1('\0'), e2{'\0'}, e3('\0'), e4('\0') {}
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is 
redundant
   // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is 
redundant
   // CHECK-MESSAGES: :[[@LINE-3]]:44: warning: member initializer for 'e3' is 
redundant
   // CHECK-FIXES: ExistingChar(long) :  e4('\0') {}
-  ExistingChar(char) : e1('a'), e2('a'), e3('a'), e4('a') {}
+  ExistingChar(char) : e1('a'), e2{'a'}, e3('a'), e4('a') {}
   // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: member initializer for 'e4' is 
redundant
-  // CHECK-FIXES: ExistingChar(char) : e1('a'), e2('a'), e3('a') {}
+  // CHECK-FIXES: ExistingChar(char) : e1('a'), e2{'a'}, e3('a') {}
   char e1{};
   char e2 = 0;
   char e3 = '\0';
@@ -272,22 +272,22 @@ struct ExistingChar {
 };
 
 struct ExistingInt {
-  ExistingInt(short) : e1(), e2(), e3(), e4(), e5(), e6() {}
+  ExistingInt(short) : e1(), e2{}, e3(), e4(), e5(), e6() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is 
redundant [modernize-use-default-member-init]
   // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is 
redundant
   // CHECK-FIXES: ExistingInt(short) :  e3(), e4(), e5(), e6() {}
-  ExistingInt(int) : e1(0), e2(0), e3(0), e4(0), e5(0), e6(0) {}
+  ExistingInt(int) : e1(0), e2{0}, e3(0), e4(0), e5(0), e6(0) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: member initializer for 'e1' is 
redundant
   // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: member initializer for 'e2' is 
redundant
   // CHECK-FIXES: ExistingInt(int) :  e3(0), e4(0), e5(0), e6(0) {}
-  ExistingInt(long) : e1(5), e2(5), e3(5), e4(5), e5(5), e6(5) {}
+  ExistingInt

[clang-tools-extra] 35f2c3a - [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for default member funcs

2020-12-20 Thread Malcolm Parsons via cfe-commits

Author: Chris Warner
Date: 2020-12-20T11:22:41Z
New Revision: 35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4

URL: 
https://github.com/llvm/llvm-project/commit/35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4
DIFF: 
https://github.com/llvm/llvm-project/commit/35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4.diff

LOG: [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for 
default member funcs

Modify the cppcoreguidelines-pro-type-member-init checker to ignore warnings 
from the move and copy-constructors when they are compiler defined with `= 
default` outside of the type declaration.

Reported as [LLVM bug 36819](https://bugs.llvm.org/show_bug.cgi?id=36819)

Reviewed By: malcolm.parsons

Differential Revision: https://reviews.llvm.org/D9

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index a223d215af1b..67856be843e7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -297,6 +297,10 @@ void ProTypeMemberInitCheck::check(const 
MatchFinder::MatchResult &Result) {
 // Skip declarations delayed by late template parsing without a body.
 if (!Ctor->getBody())
   return;
+// Skip out-of-band explicitly defaulted special member functions
+// (except the default constructor).
+if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
+  return;
 checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
 checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), 
Ctor);
   } else if (const auto *Record =

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
index 28230dd6952e..403f28baf99d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -501,3 +501,19 @@ struct NegativeImplicitInheritedCtor : 
NegativeImplicitInheritedCtorBase {
 void Bug33557() {
   NegativeImplicitInheritedCtor I(5);
 }
+
+struct NegativeDefaultedCtorOutOfDecl {
+  NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &);
+  int F;
+};
+
+NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const 
NegativeDefaultedCtorOutOfDecl &) = default;
+
+struct PositiveDefaultConstructorOutOfDecl {
+  PositiveDefaultConstructorOutOfDecl();
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = 
default;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 5389a05 - [docs] Fix documentation for bugprone-dangling-handle

2021-05-12 Thread Malcolm Parsons via cfe-commits

Author: Malcolm Parsons
Date: 2021-05-12T17:20:15+01:00
New Revision: 5389a05836e74e3acab6dbda7e80ea43e3bc6304

URL: 
https://github.com/llvm/llvm-project/commit/5389a05836e74e3acab6dbda7e80ea43e3bc6304
DIFF: 
https://github.com/llvm/llvm-project/commit/5389a05836e74e3acab6dbda7e80ea43e3bc6304.diff

LOG: [docs] Fix documentation for bugprone-dangling-handle

string_view isn't experimental anymore.
This check has always handled both forms.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D102313

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-dangling-handle.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone-dangling-handle.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone-dangling-handle.rst
index 8c2c316c090da..701b67d77acaa 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone-dangling-handle.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone-dangling-handle.rst
@@ -3,8 +3,7 @@
 bugprone-dangling-handle
 
 
-Detect dangling references in value handles like
-``std::experimental::string_view``.
+Detect dangling references in value handles like ``std::string_view``.
 These dangling references can be a result of constructing handles from 
temporary
 values, where the temporary is destroyed soon after the handle is created.
 
@@ -35,4 +34,5 @@ Options
 .. option:: HandleClasses
 
A semicolon-separated list of class names that should be treated as handles.
-   By default only ``std::experimental::basic_string_view`` is considered.
+   By default only ``std::basic_string_view`` and
+   ``std::experimental::basic_string_view`` are considered.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329813 - [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.

2018-04-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Apr 11 07:39:17 2018
New Revision: 329813

URL: http://llvm.org/viewvc/llvm-project?rev=329813&view=rev
Log:
[clang-apply-replacements] Convert tooling::Replacements to 
tooling::AtomicChange for conflict resolving of changes, code cleanup, and code 
formatting.

Summary:
By converting Replacements by AtomicChange, clang-apply-replacements is able 
like clang-tidy to automatically cleanup and format changes.
This should permits to close this ticket: 
https://bugs.llvm.org/show_bug.cgi?id=35051 and attempt to follow hints from 
https://reviews.llvm.org/D43500 comments.

Reviewers: klimek, ioeric

Reviewed By: ioeric

Subscribers: malcolm.parsons, mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D43764

Patch by Jeremy Demeule.

Added:
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/identical.cpp

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/order-dependent/

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/order-dependent/expected.txt

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/order-dependent/file1.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/order-dependent/file2.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/order-dependent/order-dependent.cpp
clang-tools-extra/trunk/test/clang-apply-replacements/identical.cpp
clang-tools-extra/trunk/test/clang-apply-replacements/order-dependent.cpp
Removed:

clang-tools-extra/trunk/unittests/clang-apply-replacements/ReformattingTest.cpp
Modified:

clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h

clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt

clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/expected.txt

clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt

Modified: 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h?rev=329813&r1=329812&r2=329813&view=diff
==
--- 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 (original)
+++ 
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 Wed Apr 11 07:39:17 2018
@@ -18,6 +18,7 @@
 
 #include "clang/Tooling/Core/Diagnostic.h"
 #include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -29,15 +30,8 @@ namespace clang {
 class DiagnosticsEngine;
 class Rewriter;
 
-namespace format {
-struct FormatStyle;
-} // end namespace format
-
 namespace replace {
 
-/// \brief Collection of source ranges.
-typedef std::vector RangeVector;
-
 /// \brief Collection of TranslationUnitReplacements.
 typedef std::vector 
TUReplacements;
 
@@ -47,10 +41,10 @@ typedef std::vector TURepla
 /// \brief Collection of TranslationUniDiagnostics.
 typedef std::vector TUDiagnostics;
 
-/// \brief Map mapping file name to Replacements targeting that file.
+/// \brief Map mapping file name to a set of AtomicChange targeting that file.
 typedef llvm::DenseMap>
-FileToReplacementsMap;
+   std::vector>
+FileToChangesMap;
 
 /// \brief Recursively descends through a directory structure rooted at \p
 /// Directory and attempts to deserialize *.yaml files as
@@ -77,65 +71,39 @@ std::error_code collectReplacementsFromD
 const llvm::StringRef Directory, TUDiagnostics &TUs,
 TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics);
 
-/// \brief Deduplicate, check for conflicts, and apply all Replacements stored
-/// in \c TUs. If conflicts occur, no Replacements are applied.
+/// \brief Deduplicate, check for conflicts, and extract all Replacements 
stored
+/// in \c TUs. Conflicting replacements are skipped.
 ///
-/// \post For all (key,value) in GroupedReplacements, value[i].getOffset() <=
+/// \post For all (key,value) in FileChanges, value[i].getOffset() <=
 /// value[i+1].getOffset().
 ///
 /// \param[in] TUs Collection of TranslationUnitReplacements or
-/// Tran

r318827 - [Docs] Update list of languages clang-format can format

2017-11-22 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Nov 22 02:47:35 2017
New Revision: 318827

URL: http://llvm.org/viewvc/llvm-project?rev=318827&view=rev
Log:
[Docs] Update list of languages clang-format can format

Modified:
cfe/trunk/docs/ClangFormat.rst

Modified: cfe/trunk/docs/ClangFormat.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=318827&r1=318826&r2=318827&view=diff
==
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Wed Nov 22 02:47:35 2017
@@ -11,7 +11,7 @@ Standalone Tool
 ===
 
 :program:`clang-format` is located in `clang/tools/clang-format` and can be 
used
-to format C/C++/Obj-C code.
+to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
 
 .. code-block:: console
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r289797 - [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-15 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Thu Dec 15 04:19:56 2016
New Revision: 289797

URL: http://llvm.org/viewvc/llvm-project?rev=289797&view=rev
Log:
[clang-tidy] Enhance modernize-use-auto to templated function casts

Summary:
Use auto when declaring variables that are initialized by calling a templated
function that returns its explicit first argument.

Fixes PR26763.

Reviewers: aaron.ballman, alexfh, staronj, Prazek

Subscribers: Eugene.Zelenko, JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D27166

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=289797&r1=289796&r2=289797&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Thu Dec 15 
04:19:56 2016
@@ -24,6 +24,7 @@ namespace {
 const char IteratorDeclStmtId[] = "iterator_decl";
 const char DeclWithNewId[] = "decl_new";
 const char DeclWithCastId[] = "decl_cast";
+const char DeclWithTemplateCastId[] = "decl_template";
 
 /// \brief Matches variable declarations that have explicit initializers that
 /// are not initializer lists.
@@ -169,6 +170,14 @@ AST_MATCHER(Decl, isFromStdNamespace) {
   return (Info && Info->isStr("std"));
 }
 
+/// Matches declaration reference or member expressions with explicit template
+/// arguments.
+AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
+AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
+MemberExpr)) {
+  return Node.hasExplicitTemplateArgs();
+}
+
 /// \brief Returns a DeclarationMatcher that matches standard iterators nested
 /// inside records with a standard container name.
 DeclarationMatcher standardIterator() {
@@ -240,18 +249,38 @@ StatementMatcher makeDeclWithCastMatcher
   .bind(DeclWithCastId);
 }
 
+StatementMatcher makeDeclWithTemplateCastMatcher() {
+  auto ST =
+  substTemplateTypeParmType(hasReplacementType(equalsBoundNode("arg")));
+
+  auto ExplicitCall =
+  anyOf(has(memberExpr(hasExplicitTemplateArgs())),
+has(ignoringImpCasts(declRefExpr(hasExplicitTemplateArgs();
+
+  auto TemplateArg =
+  hasTemplateArgument(0, refersToType(qualType().bind("arg")));
+
+  auto TemplateCall = callExpr(
+  ExplicitCall,
+  callee(functionDecl(TemplateArg,
+  returns(anyOf(ST, pointsTo(ST), references(ST));
+
+  return declStmt(unless(has(varDecl(
+  
unless(hasInitializer(ignoringImplicit(TemplateCall)))
+  .bind(DeclWithTemplateCastId);
+}
+
 StatementMatcher makeCombinedMatcher() {
   return declStmt(
   // At least one varDecl should be a child of the declStmt to ensure
   // it's a declaration list and avoid matching other declarations,
   // e.g. using directives.
-  has(varDecl()),
+  has(varDecl(unless(isImplicit(,
   // Skip declarations that are already using auto.
   unless(has(varDecl(anyOf(hasType(autoType()),
-   hasType(pointerType(pointee(autoType(,
-   hasType(referenceType(pointee(autoType(,
+   
hasType(qualType(hasDescendant(autoType(,
   anyOf(makeIteratorDeclMatcher(), makeDeclWithNewMatcher(),
-makeDeclWithCastMatcher()));
+makeDeclWithCastMatcher(), makeDeclWithTemplateCastMatcher()));
 }
 
 } // namespace
@@ -389,6 +418,8 @@ void UseAutoCheck::replaceExpr(const Dec
 
   // Space after 'auto' to handle cases where the '*' in the pointer type is
   // next to the identifier. This avoids changing 'int *p' into 'autop'.
+  // FIXME: This doesn't work for function pointers because the variable name
+  // is inside the type.
   Diag << FixItHint::CreateReplacement(Range, RemoveStars ? "auto " : "auto")
<< StarRemovals;
 }
@@ -411,6 +442,17 @@ void UseAutoCheck::check(const MatchFind
 },
 "use auto when initializing with a cast to avoid duplicating the type "
 "name");
+  } else if (const auto *Decl =
+ Result.Nodes.getNodeAs(DeclWithTemplateCastId)) {
+replaceExpr(
+Decl, Result.Context,
+[](const Expr *Expr) {
+  return cast(Expr->IgnoreImplicit())
+  ->getDirectCallee()
+  ->getReturnType();
+},
+"use auto when initializing with a template cast to avoid duplicating "
+

[clang-tools-extra] r290051 - [clang-tidy] Remove duplicated check from move-constructor-init

2016-12-17 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Sat Dec 17 14:23:14 2016
New Revision: 290051

URL: http://llvm.org/viewvc/llvm-project?rev=290051&view=rev
Log:
[clang-tidy] Remove duplicated check from move-constructor-init

Summary:
An addition to the move-constructor-init check was duplicating the
modernize-pass-by-value check.
Remove the additional check and UseCERTSemantics option.
Run the move-constructor-init test with both checks enabled.
Fix modernize-pass-by-value false-positive when initializing a base
class.
Add option to modernize-pass-by-value to only warn about parameters
that are already values.

Reviewers: alexfh, flx, aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26453

Modified:
clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst
clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp?rev=290051&r1=290050&r2=290051&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp Sat Dec 17 
14:23:14 2016
@@ -67,11 +67,6 @@ public:
 // MSC
 CheckFactories.registerCheck("cert-msc30-c");
   }
-  ClangTidyOptions getModuleOptions() override {
-ClangTidyOptions Options;
-Options.CheckOptions["cert-oop11-cpp.UseCERTSemantics"] = "1";
-return Options;
-  }
 };
 
 } // namespace cert

Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp?rev=290051&r1=290050&r2=290051&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp Sat 
Dec 17 14:23:14 2016
@@ -21,30 +21,11 @@ namespace clang {
 namespace tidy {
 namespace misc {
 
-namespace {
-
-unsigned int
-parmVarDeclRefExprOccurences(const ParmVarDecl &MovableParam,
- const CXXConstructorDecl &ConstructorDecl,
- ASTContext &Context) {
-  unsigned int Occurrences = 0;
-  auto AllDeclRefs =
-  findAll(declRefExpr(to(parmVarDecl(equalsNode(&MovableParam);
-  Occurrences += match(AllDeclRefs, *ConstructorDecl.getBody(), 
Context).size();
-  for (const auto *Initializer : ConstructorDecl.inits()) {
-Occurrences += match(AllDeclRefs, *Initializer->getInit(), Context).size();
-  }
-  return Occurrences;
-}
-
-} // namespace
-
 MoveConstructorInitCheck::MoveConstructorInitCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
-  Options.get("IncludeStyle", "llvm"))),
-  UseCERTSemantics(Options.get("UseCERTSemantics", 0) != 0) {}
+  Options.get("IncludeStyle", "llvm"))) {}
 
 void MoveConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++11; the functionality currently does not
@@ -63,68 +44,9 @@ void MoveConstructorInitCheck::registerM
 .bind("ctor")
 .bind("move-init",
   this);
-
-  auto NonConstValueMovableAndExpensiveToCopy =
-  qualType(allOf(unless(pointerType()), unless(isConstQualified()),
- hasDeclaration(cxxRecordDecl(hasMethod(cxxConstructorDecl(
- isMoveConstructor(), unless(isDeleted()),
- matchers::isExpensiveToCopy()));
-
-  // This checker is also used to implement cert-oop11-cpp, but when using that
-  // form of the checker, we do not want to diagnose movable parameters.
-  if (!UseCERTSemantics) {
-Finder->addMatcher(
-cxxConstructorDecl(
-allOf(
-unless(isMoveConstructor()),
-hasAnyConstructorInitializer(withInitializer(cxxConstructExpr(
-hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
-hasArgument(
-0,
- 

[clang-tools-extra] r290202 - [clang-tidy] Add modernize-use-default-member-init check

2016-12-20 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Dec 20 15:26:07 2016
New Revision: 290202

URL: http://llvm.org/viewvc/llvm-project?rev=290202&view=rev
Log:
[clang-tidy] Add modernize-use-default-member-init check

Summary: Fixes PR18858

Reviewers: alexfh, hokein, aaron.ballman

Subscribers: JDevlieghere, Eugene.Zelenko, Prazek, mgorny, cfe-commits, 
modocache

Differential Revision: https://reviews.llvm.org/D26750

Added:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-default-member-init.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.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/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=290202&r1=290201&r2=290202&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Tue Dec 20 
15:26:07 2016
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModu
   ShrinkToFitCheck.cpp
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
+  UseDefaultMemberInitCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp?rev=290202&r1=290201&r2=290202&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp Tue 
Dec 20 15:26:07 2016
@@ -22,6 +22,7 @@
 #include "ShrinkToFitCheck.h"
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
+#include "UseDefaultMemberInitCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -56,6 +57,8 @@ public:
 CheckFactories.registerCheck("modernize-use-auto");
 CheckFactories.registerCheck(
 "modernize-use-bool-literals");
+CheckFactories.registerCheck(
+"modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
 
CheckFactories.registerCheck("modernize-use-equals-default");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=290202&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Tue Dec 20 15:26:07 2016
@@ -0,0 +1,241 @@
+//===--- UseDefaultMemberInitCheck.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 "UseDefaultMemberInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+static StringRef getValueOfValueInit(const QualType InitType) {
+  switch (InitType->getScalarTypeKind()) {
+  case Type::STK_CPointer:
+  case Type::STK_BlockPointer:
+  case Type::STK_ObjCObjectPointer:
+  case Type::STK_MemberPointer:
+return "nullptr";
+
+  case Type::STK_Bool:
+return "false";
+
+  case Type::STK_Integral:
+switch (InitType->getAs()->getKind()) {
+case BuiltinType::Char_U:
+case BuiltinType::UChar:
+case BuiltinType::Char_S:
+case BuiltinType::SChar:
+  return "'\\0'";
+case BuiltinType::WChar_U:
+case BuiltinType::WChar_S:
+  return "L'\\0'";
+case BuiltinType::Char16:
+  return "u'\\0'";
+case BuiltinType::Char32:
+  return "U'\\0'";
+default:
+  return "0";
+}
+
+  case Type::STK_Floating:
+switch (InitType->getAs()->getKind()) {
+case BuiltinType::Half:
+case BuiltinType::Float:
+  return "0.0f";
+defa

Re: [clang-tools-extra] r290202 - [clang-tidy] Add modernize-use-default-member-init check

2016-12-20 Thread Malcolm Parsons via cfe-commits
On 20 December 2016 at 22:32, Aaron Ballman  wrote:
> On Tue, Dec 20, 2016 at 4:26 PM, Malcolm Parsons via cfe-commits
>  wrote:
>> Author: malcolm.parsons
>> Date: Tue Dec 20 15:26:07 2016
>> New Revision: 290202
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=290202&view=rev
>> Log:
>> [clang-tidy] Add modernize-use-default-member-init check
>>
>> Summary: Fixes PR18858
>
> This appears to have broken one of the bots:
>
> http://bb.pgr.jp/builders/ninja-x64-msvc-RA-centos6/builds/33046

error: unknown type name 'char16_t'
error: unknown type name 'char32_t'

I see commented tests in other clang-tidy tests:

// TODO: enable these tests once all supported compilers
// support char16_t and char32_t (VS2013 does not)

// disabled for now until it is clear
// how to enable them in the test
//} catch (const char16_t*) {

-- 
Malcolm Parsons
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r290210 - Comment out char16_t and char32_t tests

2016-12-20 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Dec 20 16:57:21 2016
New Revision: 290210

URL: http://llvm.org/viewvc/llvm-project?rev=290210&view=rev
Log:
Comment out char16_t and char32_t tests

Modified:

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp?rev=290210&r1=290209&r2=290210&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-assignment.cpp
 Tue Dec 20 16:57:21 2016
@@ -5,7 +5,7 @@ struct S {
 };
 
 struct PositiveValueChar {
-  PositiveValueChar() : c0(), c1(), c2(), c3() {}
+  PositiveValueChar() : c0(), c1()/*, c2(), c3()*/ {}
   // CHECK-FIXES: PositiveValueChar()  {}
   const char c0;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use default member initializer 
for 'c0' [modernize-use-default-member-init]
@@ -13,12 +13,12 @@ struct PositiveValueChar {
   wchar_t c1;
   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer 
for 'c1'
   // CHECK-FIXES: wchar_t c1 = L'\0';
-  char16_t c2;
-  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c2'
-  // CHECK-FIXES: char16_t c2 = u'\0';
-  char32_t c3;
-  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c3'
-  // CHECK-FIXES: char32_t c3 = U'\0';
+  // FIXME: char16_t c2;
+  // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c2'
+  // C HECK-FIXES: char16_t c2 = u'\0';
+  // FIXME: char32_t c3;
+  // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c3'
+  // C HECK-FIXES: char32_t c3 = U'\0';
 };
 
 struct PositiveChar {

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=290210&r1=290209&r2=290210&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
Tue Dec 20 16:57:21 2016
@@ -4,7 +4,7 @@ struct S {
 };
 
 struct PositiveValueChar {
-  PositiveValueChar() : c0(), c1(), c2(), c3() {}
+  PositiveValueChar() : c0(), c1()/*, c2(), c3()*/ {}
   // CHECK-FIXES: PositiveValueChar()  {}
   const char c0;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use default member initializer 
for 'c0' [modernize-use-default-member-init]
@@ -12,12 +12,12 @@ struct PositiveValueChar {
   wchar_t c1;
   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer 
for 'c1'
   // CHECK-FIXES: wchar_t c1{};
-  char16_t c2;
-  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c2'
-  // CHECK-FIXES: char16_t c2{};
-  char32_t c3;
-  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c3'
-  // CHECK-FIXES: char32_t c3{};
+  // FIXME: char16_t c2;
+  // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c2'
+  // C HECK-FIXES: char16_t c2{};
+  // FIXME: char32_t c3;
+  // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer 
for 'c3'
+  // C HECK-FIXES: char32_t c3{};
 };
 
 struct PositiveChar {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290491 - [ASTMatchers] Fix doc for hasBitWidth

2016-12-24 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Sat Dec 24 07:22:26 2016
New Revision: 290491

URL: http://llvm.org/viewvc/llvm-project?rev=290491&view=rev
Log:
[ASTMatchers] Fix doc for hasBitWidth

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=290491&r1=290490&r2=290491&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Sat Dec 24 07:22:26 2016
@@ -2430,7 +2430,8 @@ designatorCountIs(2)
 
 
 MatcherFieldDecl>hasBitWidthunsigned Width
-Matches non-static data 
members that are bit-fields.
+Matches non-static data 
members that are bit-fields of the specified
+bit width.
 
 Given
   class C {
@@ -2438,7 +2439,7 @@ Given
 int b : 4;
 int c : 2;
   };
-fieldDecl(isBitField())
+fieldDecl(hasBitWidth(2))
   matches 'int a;' and 'int c;' but not 'int b;'.
 
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=290491&r1=290490&r2=290491&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sat Dec 24 07:22:26 2016
@@ -533,7 +533,8 @@ AST_MATCHER(FieldDecl, isBitField) {
   return Node.isBitField();
 }
 
-/// \brief Matches non-static data members that are bit-fields.
+/// \brief Matches non-static data members that are bit-fields of the specified
+/// bit width.
 ///
 /// Given
 /// \code
@@ -543,7 +544,7 @@ AST_MATCHER(FieldDecl, isBitField) {
 /// int c : 2;
 ///   };
 /// \endcode
-/// fieldDecl(isBitField())
+/// fieldDecl(hasBitWidth(2))
 ///   matches 'int a;' and 'int c;' but not 'int b;'.
 AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width) {
   return Node.isBitField() &&


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290492 - [ASTMatchers] Add hasInClassInitializer traversal matcher for FieldDecl.

2016-12-24 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Sat Dec 24 07:35:14 2016
New Revision: 290492

URL: http://llvm.org/viewvc/llvm-project?rev=290492&view=rev
Log:
[ASTMatchers] Add hasInClassInitializer traversal matcher for FieldDecl.

Summary:
I needed to know whether a FieldDecl had an in-class
initializer for D26453. I used a narrowing matcher there, but a
traversal matcher might be generally useful.

Reviewers: sbenza, bkramer, klimek, aaron.ballman

Subscribers: aaron.ballman, Prazek, cfe-commits

Differential Revision: https://reviews.llvm.org/D28034

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=290492&r1=290491&r2=290492&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Sat Dec 24 07:35:14 2016
@@ -4751,6 +4751,22 @@ would only match the declaration for a.
 
 
 
+MatcherFieldDecl>hasInClassInitializerMatcherExpr> 
InnerMatcher
+Matches 
non-static data members that have an in-class initializer.
+
+Given
+  class C {
+int a = 2;
+int b = 3;
+int c;
+  };
+fieldDecl(hasInClassInitializer(integerLiteral(equals(2
+  matches 'int a;' but not 'int b;'.
+fieldDecl(hasInClassInitializer(anything()))
+  matches 'int a;' and 'int b;' but not 'int c;'.
+
+
+
 MatcherForStmt>hasBodyMatcherStmt> 
InnerMatcher
 Matches a 'for', 'while', 
'do while' statement or a function
 definition that has a given body.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=290492&r1=290491&r2=290492&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sat Dec 24 07:35:14 2016
@@ -551,6 +551,27 @@ AST_MATCHER_P(FieldDecl, hasBitWidth, un
  Node.getBitWidthValue(Finder->getASTContext()) == Width;
 }
 
+/// \brief Matches non-static data members that have an in-class initializer.
+///
+/// Given
+/// \code
+///   class C {
+/// int a = 2;
+/// int b = 3;
+/// int c;
+///   };
+/// \endcode
+/// fieldDecl(hasInClassInitializer(integerLiteral(equals(2
+///   matches 'int a;' but not 'int b;'.
+/// fieldDecl(hasInClassInitializer(anything()))
+///   matches 'int a;' and 'int b;' but not 'int c;'.
+AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher,
+  InnerMatcher) {
+  const Expr *Initializer = Node.getInClassInitializer();
+  return (Initializer != nullptr &&
+  InnerMatcher.matches(*Initializer, Finder, Builder));
+}
+
 /// \brief Matches a declaration that has been implicitly added
 /// by the compiler (eg. implicit default/copy constructors).
 AST_MATCHER(Decl, isImplicit) {

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=290492&r1=290491&r2=290492&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Sat Dec 24 07:35:14 2016
@@ -232,6 +232,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasFalseExpression);
   REGISTER_MATCHER(hasGlobalStorage);
   REGISTER_MATCHER(hasImplicitDestinationType);
+  REGISTER_MATCHER(hasInClassInitializer);
   REGISTER_MATCHER(hasIncrement);
   REGISTER_MATCHER(hasIndex);
   REGISTER_MATCHER(hasInitializer);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=290492&r1=290491&r2=290492&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Sat Dec 24 
07:35:14 2016
@@ -1404,6 +1404,16 @@ TEST(Member, BitFields) {
   fieldDecl(isBitField(), hasBitWidth(2), hasName("a";
 }
 
+TEST(Member, InClassInitializer) {
+  EXPECT_TRUE(
+  matches("class C { int a = 2; int b; };",
+  fieldDecl(hasInClassInitializer(integerLiteral(equals(2))),
+hasName("a";
+  EXPECT_TRUE(
+  notMatches

[clang-tools-extra] r290493 - [clang-tidy] Remove local hasInClassInitializer matcher. NFC

2016-12-24 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Sat Dec 24 08:30:29 2016
New Revision: 290493

URL: http://llvm.org/viewvc/llvm-project?rev=290493&view=rev
Log:
[clang-tidy] Remove local hasInClassInitializer matcher. NFC

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=290493&r1=290492&r2=290493&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Sat Dec 24 08:30:29 2016
@@ -146,10 +146,6 @@ void UseDefaultMemberInitCheck::storeOpt
   Options.store(Opts, "UseAssignment", UseAssignment);
 }
 
-AST_MATCHER(FieldDecl, hasInClassInitializer) {
-  return Node.hasInClassInitializer();
-}
-
 void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
 return;
@@ -167,18 +163,19 @@ void UseDefaultMemberInitCheck::register
   Finder->addMatcher(
   cxxConstructorDecl(
   isDefaultConstructor(), unless(isInstantiated()),
-  forEachConstructorInitializer(allOf(
-  forField(unless(anyOf(isBitField(), hasInClassInitializer(,
-  cxxCtorInitializer(isWritten(),
- withInitializer(ignoringImplicit(Init)))
-  .bind("default",
+  forEachConstructorInitializer(
+  allOf(forField(unless(anyOf(isBitField(),
+  hasInClassInitializer(anything(),
+cxxCtorInitializer(isWritten(),
+   withInitializer(ignoringImplicit(Init)))
+.bind("default",
   this);
 
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(ast_matchers::isTemplateInstantiation()),
   forEachConstructorInitializer(
-  allOf(forField(hasInClassInitializer()),
+  allOf(forField(hasInClassInitializer(anything())),
 cxxCtorInitializer(isWritten(),
withInitializer(ignoringImplicit(Init)))
 .bind("existing",


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r290630 - [clang-tidy] Replace dead link in modernize-pass-by-value doc

2016-12-27 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Dec 27 16:01:37 2016
New Revision: 290630

URL: http://llvm.org/viewvc/llvm-project?rev=290630&view=rev
Log:
[clang-tidy] Replace dead link in modernize-pass-by-value doc

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst?rev=290630&r1=290629&r2=290630&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst 
Tue Dec 27 16:01:37 2016
@@ -150,7 +150,7 @@ Example:
 
   For more information about the pass-by-value idiom, read: `Want Speed? Pass 
by Value`_.
 
-  .. _Want Speed? Pass by Value: 
http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
+  .. _Want Speed? Pass by Value: 
https://web.archive.org/web/20140205194657/http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
 
 Options
 ---


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r290633 - [clang-tidy] Make 2 checks register matchers for C++ only.

2016-12-27 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Dec 27 16:14:40 2016
New Revision: 290633

URL: http://llvm.org/viewvc/llvm-project?rev=290633&view=rev
Log:
[clang-tidy] Make 2 checks register matchers for C++ only.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp?rev=290633&r1=290632&r2=290633&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp Tue 
Dec 27 16:14:40 2016
@@ -22,6 +22,9 @@ static const char SpecialFunction[] = "S
 static const char DeletedNotPublic[] = "DeletedNotPublic";
 
 void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
   auto PrivateSpecialFn = cxxMethodDecl(
   isPrivate(),
   anyOf(cxxConstructorDecl(anyOf(isDefaultConstructor(),

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp?rev=290633&r1=290632&r2=290633&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp 
Tue Dec 27 16:14:40 2016
@@ -22,6 +22,9 @@ namespace tidy {
 namespace readability {
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
   auto Construct =
   cxxConstructExpr(
   hasDeclaration(cxxConstructorDecl(hasParent(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r290883 - [clang-tidy] Handle constructors in performance-unnecessary-value-param

2017-01-03 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Jan  3 06:10:44 2017
New Revision: 290883

URL: http://llvm.org/viewvc/llvm-project?rev=290883&view=rev
Log:
[clang-tidy] Handle constructors in performance-unnecessary-value-param

Summary:
modernize-pass-by-value doesn't warn about value parameters that
cannot be moved, so performance-unnecessary-value-param should.

Reviewers: aaron.ballman, flx, alexfh

Subscribers: JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D28022

Modified:

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.h

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-delayed.cpp

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp?rev=290883&r1=290882&r2=290883&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
Tue Jan  3 06:10:44 2017
@@ -47,14 +47,14 @@ bool isReferencedOutsideOfCallExpr(const
   return !Matches.empty();
 }
 
-bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Stmt &Stmt,
+bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
  ASTContext &Context) {
   auto Matches =
-  match(findAll(declRefExpr(
+  match(decl(forEachDescendant(declRefExpr(
 equalsNode(&DeclRef),
 unless(hasAncestor(stmt(anyOf(forStmt(), cxxForRangeStmt(),
-  whileStmt(), doStmt())),
-Stmt, Context);
+  whileStmt(), doStmt(,
+Decl, Context);
   return Matches.empty();
 }
 
@@ -72,7 +72,7 @@ void UnnecessaryValueParamCheck::registe
  unless(referenceType(),
   decl().bind("param"));
   Finder->addMatcher(
-  functionDecl(isDefinition(),
+  functionDecl(hasBody(stmt()), isDefinition(),
unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
unless(isInstantiated()),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
@@ -89,22 +89,13 @@ void UnnecessaryValueParamCheck::check(c
   bool IsConstQualified =
   Param->getType().getCanonicalType().isConstQualified();
 
-  // Skip declarations delayed by late template parsing without a body.
-  if (!Function->getBody())
-return;
-
-  // Do not trigger on non-const value parameters when:
-  // 1. they are in a constructor definition since they can likely trigger
-  //modernize-pass-by-value which will suggest to move the argument.
-  if (!IsConstQualified && (llvm::isa(Function) ||
-!Function->doesThisDeclarationHaveABody()))
-return;
-
   auto AllDeclRefExprs = utils::decl_ref_expr::allDeclRefExprs(
-  *Param, *Function->getBody(), *Result.Context);
+  *Param, *Function, *Result.Context);
   auto ConstDeclRefExprs = utils::decl_ref_expr::constReferenceDeclRefExprs(
-  *Param, *Function->getBody(), *Result.Context);
-  // 2. they are not only used as const.
+  *Param, *Function, *Result.Context);
+
+  // Do not trigger on non-const value parameters when they are not only used 
as
+  // const.
   if (!isSubset(AllDeclRefExprs, ConstDeclRefExprs))
 return;
 
@@ -113,20 +104,18 @@ void UnnecessaryValueParamCheck::check(c
   // move assignment operator and is only referenced once when copy-assigned.
   // In this case wrap DeclRefExpr with std::move() to avoid the unnecessary
   // copy.
-  if (!IsConstQualified) {
+  if (!IsConstQualified && AllDeclRefExprs.size() == 1) {
 auto CanonicalType = Param->getType().getCanonicalType();
-if (AllDeclRefExprs.size() == 1 &&
-!hasLoopStmtAncestor(**AllDeclRefExprs.begin(), *Function->getBody(),
- *Result.Context) &&
+const auto &DeclRefExpr  = **AllDeclRefExprs.begin();
+
+if (!hasLoopStmtAncestor(DeclRefExpr, *Function, *Result.Context) &&
 ((utils::type_traits::hasNonTrivialMoveConstructor(CanonicalType) &&
   utils::decl_ref_expr::isCopyConstructorArgument(
-  **AllDeclRefExprs.begin(), *Function->getBody(),
-  *Result.Context)) ||
+  DeclRefExpr, *Function, *Result.Context)) ||
  (utils::type_traits::hasNonTrivialMoveAssignment(CanonicalType) &&
   utils::decl_ref_expr::isCopyAssignmentArgument(
-  **AllDeclRefExprs.begin(), *Function->getBody

[clang-tools-extra] r290972 - [clang-tidy] Ignore default arguments in modernize-default-member-init

2017-01-04 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Jan  4 11:33:55 2017
New Revision: 290972

URL: http://llvm.org/viewvc/llvm-project?rev=290972&view=rev
Log:
[clang-tidy] Ignore default arguments in modernize-default-member-init

Summary:
Default member initializers cannot refer to constructor parameters, but 
modernize-default-member-init was trying to when the default constructor had 
default arguments.

Change the check to ignore default arguments to the default constructor.

Fixes PR31524.

Reviewers: alexfh, aaron.ballman

Subscribers: cfe-commits, JDevlieghere, Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D28287

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=290972&r1=290971&r2=290972&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Wed Jan  4 11:33:55 2017
@@ -158,7 +158,7 @@ void UseDefaultMemberInitCheck::register
 unaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-")),
   hasUnaryOperand(floatLiteral())),
 cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
-declRefExpr());
+declRefExpr(to(enumConstantDecl(;
 
   Finder->addMatcher(
   cxxConstructorDecl(

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=290972&r1=290971&r2=290972&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp 
Wed Jan  4 11:33:55 2017
@@ -221,6 +221,12 @@ struct NegativeNotDefaultInt
   int i;
 };
 
+struct NegativeDefaultArg
+{
+  NegativeDefaultArg(int i = 4) : i(i) {}
+  int i;
+};
+
 struct ExistingChar {
   ExistingChar(short) : e1(), e2(), e3(), e4() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is 
redundant [modernize-use-default-member-init]


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r291667 - Remove repeated word in comment (NFC)

2017-01-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Jan 11 05:23:22 2017
New Revision: 291667

URL: http://llvm.org/viewvc/llvm-project?rev=291667&view=rev
Log:
Remove repeated word in comment (NFC)

Modified:
cfe/trunk/lib/Parse/ParseExprCXX.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=291667&r1=291666&r2=291667&view=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Jan 11 05:23:22 2017
@@ -735,7 +735,7 @@ ExprResult Parser::TryParseLambdaExpress
 ///sometimes skip the initializers for init-captures and not fully
 ///populate \p Intro. This flag will be set to \c true if we do so.
 /// \return A DiagnosticID if it hit something unexpected. The location for
-/// for the diagnostic is that of the current token.
+/// the diagnostic is that of the current token.
 Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
  bool *SkippedInits) {
   typedef Optional DiagResult;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-17 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added a subscriber: malcolm.parsons.


Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:32-33
@@ -31,1 +31,4 @@
 
+  // Calling make_smart_ptr from within a member function of a type with a
+  // private or protected constructor would be ill-formed.
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(

The private constructor could also be called from a friend class.


https://reviews.llvm.org/D23343



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >