[clang-tools-extra] r267933 - [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:20:01 PDT 2016
Author: alexfh
Date: Thu Apr 28 15:20:01 2016
New Revision: 267933
URL: http://llvm.org/viewvc/llvm-project?rev=267933&view=rev
Log:
[clang-tidy] cppcoreguidelines-pro-type-member-init should not complain about static variables
Summary:
Variables with static storage duration are zero-initialized per
[stmt.dcl]p4 and [basic.start.init]p2.
Reviewers: sbenza, aaron.ballman
Subscribers: michael_miller, flx, cfe-commits
Differential Revision: http://reviews.llvm.org/D19672
Modified:
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
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=267933&r1=267932&r2=267933&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp Thu Apr 28 15:20:01 2016
@@ -281,6 +281,7 @@ void ProTypeMemberInitCheck::registerMat
isDefaultConstructor(), unless(isUserProvided())))));
Finder->addMatcher(
varDecl(isDefinition(), HasDefaultConstructor,
+ hasAutomaticStorageDuration(),
hasType(recordDecl(has(fieldDecl()),
isTriviallyDefaultConstructible())))
.bind("var"),
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst?rev=267933&r1=267932&r2=267933&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst Thu Apr 28 15:20:01 2016
@@ -19,10 +19,10 @@ The check takes assignment of fields in
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
-------------------
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=267933&r1=267932&r2=267933&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 Thu Apr 28 15:20:01 2016
@@ -175,17 +175,14 @@ static void PositiveComplexNonTrivialTyp
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 @@ struct InheritedAggregate : public Negat
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 PositiveCStructVariable() {
}
}
+static void NegativeStaticVariable() {
+ static NegativeCStruct S;
+ (void)S;
+}
+
union NegativeUnionInClass {
NegativeUnionInClass() {} // No message as a union can only initialize one member.
int X = 0;
More information about the cfe-commits
mailing list