forked from OSchip/llvm-project
Rename -Wself-assign-memvar to -Wself-assign-field to improve local consistency a bit.
(cf -Wunused-private-field and several other existing -field diagnostics.) llvm-svn: 159633
This commit is contained in:
parent
c4702dac1c
commit
b8124d1af1
|
@ -169,8 +169,8 @@ def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">;
|
|||
def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>;
|
||||
def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy",
|
||||
[CXX98CompatBindToTemporaryCopy]>;
|
||||
def SelfAssignmentMemvar : DiagGroup<"self-assign-memvar">;
|
||||
def SelfAssignment : DiagGroup<"self-assign", [SelfAssignmentMemvar]>;
|
||||
def SelfAssignmentField : DiagGroup<"self-assign-field">;
|
||||
def SelfAssignment : DiagGroup<"self-assign", [SelfAssignmentField]>;
|
||||
def SemiBeforeMethodBody : DiagGroup<"semicolon-before-method-body">;
|
||||
def Sentinel : DiagGroup<"sentinel">;
|
||||
def MissingMethodReturnType : DiagGroup<"missing-method-return-type">;
|
||||
|
|
|
@ -5283,9 +5283,9 @@ def warn_stringcompare : Warning<
|
|||
"unspecified (use strncmp instead)">,
|
||||
InGroup<DiagGroup<"string-compare">>;
|
||||
|
||||
def warn_identity_memvar_assign : Warning<
|
||||
"assigning %select{member variable|instance variable}0 to itself">,
|
||||
InGroup<SelfAssignmentMemvar>;
|
||||
def warn_identity_field_assign : Warning<
|
||||
"assigning %select{field|instance variable}0 to itself">,
|
||||
InGroup<SelfAssignmentField>;
|
||||
|
||||
// Generic selections.
|
||||
def err_assoc_type_incomplete : Error<
|
||||
|
|
|
@ -7558,25 +7558,25 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static void CheckIdentityMemvarAssignment(Expr *LHSExpr, Expr *RHSExpr,
|
||||
SourceLocation Loc,
|
||||
Sema &Sema) {
|
||||
// C / C++ memvars
|
||||
static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr,
|
||||
SourceLocation Loc,
|
||||
Sema &Sema) {
|
||||
// C / C++ fields
|
||||
MemberExpr *ML = dyn_cast<MemberExpr>(LHSExpr);
|
||||
MemberExpr *MR = dyn_cast<MemberExpr>(RHSExpr);
|
||||
if (ML && MR && ML->getMemberDecl() == MR->getMemberDecl()) {
|
||||
if (isa<CXXThisExpr>(ML->getBase()) && isa<CXXThisExpr>(MR->getBase()))
|
||||
Sema.Diag(Loc, diag::warn_identity_memvar_assign) << 0;
|
||||
Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
|
||||
}
|
||||
|
||||
// Objective-C memvars
|
||||
// Objective-C instance variables
|
||||
ObjCIvarRefExpr *OL = dyn_cast<ObjCIvarRefExpr>(LHSExpr);
|
||||
ObjCIvarRefExpr *OR = dyn_cast<ObjCIvarRefExpr>(RHSExpr);
|
||||
if (OL && OR && OL->getDecl() == OR->getDecl()) {
|
||||
DeclRefExpr *RL = dyn_cast<DeclRefExpr>(OL->getBase()->IgnoreImpCasts());
|
||||
DeclRefExpr *RR = dyn_cast<DeclRefExpr>(OR->getBase()->IgnoreImpCasts());
|
||||
if (RL && RR && RL->getDecl() == RR->getDecl())
|
||||
Sema.Diag(Loc, diag::warn_identity_memvar_assign) << 1;
|
||||
Sema.Diag(Loc, diag::warn_identity_field_assign) << 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7597,7 +7597,7 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS,
|
|||
if (CompoundType.isNull()) {
|
||||
Expr *RHSCheck = RHS.get();
|
||||
|
||||
CheckIdentityMemvarAssignment(LHSExpr, RHSCheck, Loc, *this);
|
||||
CheckIdentityFieldAssignment(LHSExpr, RHSCheck, Loc, *this);
|
||||
|
||||
QualType LHSTy(LHSType);
|
||||
ConvTy = CheckSingleAssignmentConstraints(LHSTy, RHS);
|
||||
|
|
|
@ -4,10 +4,10 @@ class S {
|
|||
public:
|
||||
int a_;
|
||||
void s(int a) {
|
||||
a_ = a_; // expected-warning {{assigning member variable to itself}}
|
||||
a_ = a_; // expected-warning {{assigning field to itself}}
|
||||
|
||||
// Don't really care about this one either way.
|
||||
this->a_ = a_; // expected-warning {{assigning member variable to itself}}
|
||||
this->a_ = a_; // expected-warning {{assigning field to itself}}
|
||||
|
||||
a_ += a_; // Shouldn't warn.
|
||||
}
|
Loading…
Reference in New Issue