[PATCH] D19672: [clang-tidy] cppcoreguidelines-pro-type-member-init should not complain about static variables

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 13:25:55 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL267933: [clang-tidy] cppcoreguidelines-pro-type-member-init should not complain about… (authored by alexfh).

Changed prior to commit:
  http://reviews.llvm.org/D19672?vs=55441&id=55476#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19672

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

Index: clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
===================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
@@ -19,10 +19,10 @@
 account but generates false positives for fields initialized in
 methods invoked in the constructor body.
 
-The check also flags variables of record types without a user-provided
-constructor that are not initialized. The suggested fix is to zero
-initialize the variable via {} for C++11 and beyond or = {} for older
-versions.
+The check also flags variables with automatic storage duration that have record
+types without a user-provided constructor and are not initialized. The suggested
+fix is to zero initialize the variable via ``{}`` for C++11 and beyond or ``=
+{}`` for older language versions.
 
 IgnoreArrays option
 -------------------
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
@@ -175,17 +175,14 @@
   ComplexNonTrivialType T;
 }
 
-struct PositiveStaticMember {
+struct NegativeStaticMember {
   static NonTrivialType X;
   static NonTrivialType Y;
   static constexpr NonTrivialType Z{};
 };
 
-NonTrivialType PositiveStaticMember::X;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: uninitialized record type: 'X'
-// CHECK-FIXES: NonTrivialType PositiveStaticMember::X{};
-
-NonTrivialType PositiveStaticMember::Y{};
+NonTrivialType NegativeStaticMember::X;
+NonTrivialType NegativeStaticMember::Y{};
 
 struct PositiveMultipleConstructors {
   PositiveMultipleConstructors() {}
@@ -242,9 +239,7 @@
   int F;
 };
 
-static InheritedAggregate PositiveGlobal;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: uninitialized record type: 'PositiveGlobal'
-// CHECK-FIXES: InheritedAggregate PositiveGlobal{};
+static InheritedAggregate NegativeGlobal;
 
 enum TestEnum {
   A,
@@ -280,6 +275,11 @@
 }
 }
 
+static void NegativeStaticVariable() {
+  static NegativeCStruct S;
+  (void)S;
+}
+
 union NegativeUnionInClass {
   NegativeUnionInClass() {} // No message as a union can only initialize one member.
   int X = 0;
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
@@ -281,6 +281,7 @@
                            isDefaultConstructor(), unless(isUserProvided())))));
   Finder->addMatcher(
       varDecl(isDefinition(), HasDefaultConstructor,
+              hasAutomaticStorageDuration(),
               hasType(recordDecl(has(fieldDecl()),
                                  isTriviallyDefaultConstructible())))
           .bind("var"),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19672.55476.patch
Type: text/x-patch
Size: 3190 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160428/5e76a9fe/attachment-0001.bin>


More information about the cfe-commits mailing list