forked from OSchip/llvm-project
[clang][NFC] Avoid assignment in condition
Refactor to avoid assignment inside condition by using 'if (init-decl)'. Also remove some unnecessary braces on a separate if-nest. Differential Revision: https://reviews.llvm.org/D104039
This commit is contained in:
parent
789708617d
commit
691ba0f8ac
|
@ -12231,12 +12231,12 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
|
|||
// If adding the initializer will turn this declaration into a definition,
|
||||
// and we already have a definition for this variable, diagnose or otherwise
|
||||
// handle the situation.
|
||||
VarDecl *Def;
|
||||
if ((Def = VDecl->getDefinition()) && Def != VDecl &&
|
||||
(!VDecl->isStaticDataMember() || VDecl->isOutOfLine()) &&
|
||||
!VDecl->isThisDeclarationADemotedDefinition() &&
|
||||
checkVarDeclRedefinition(Def, VDecl))
|
||||
return;
|
||||
if (VarDecl *Def = VDecl->getDefinition())
|
||||
if (Def != VDecl &&
|
||||
(!VDecl->isStaticDataMember() || VDecl->isOutOfLine()) &&
|
||||
!VDecl->isThisDeclarationADemotedDefinition() &&
|
||||
checkVarDeclRedefinition(Def, VDecl))
|
||||
return;
|
||||
|
||||
if (getLangOpts().CPlusPlus) {
|
||||
// C++ [class.static.data]p4
|
||||
|
@ -12350,12 +12350,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
|
|||
// Variables declared within a function/method body (except for references)
|
||||
// are handled by a dataflow analysis.
|
||||
// This is undefined behavior in C++, but valid in C.
|
||||
if (getLangOpts().CPlusPlus) {
|
||||
if (getLangOpts().CPlusPlus)
|
||||
if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() ||
|
||||
VDecl->getType()->isReferenceType()) {
|
||||
VDecl->getType()->isReferenceType())
|
||||
CheckSelfReference(*this, RealDecl, Init, DirectInit);
|
||||
}
|
||||
}
|
||||
|
||||
// If the type changed, it means we had an incomplete type that was
|
||||
// completed by the initializer. For example:
|
||||
|
|
Loading…
Reference in New Issue