Author: Nathan Sidwell Date: 2021-06-11T03:53:55-07:00 New Revision: 691ba0f8acb511f7da1e78c59fe9560b64c47f3a
URL: https://github.com/llvm/llvm-project/commit/691ba0f8acb511f7da1e78c59fe9560b64c47f3a DIFF: https://github.com/llvm/llvm-project/commit/691ba0f8acb511f7da1e78c59fe9560b64c47f3a.diff LOG: [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 Added: Modified: clang/lib/Sema/SemaDecl.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 389c8505486f..263edbb8add5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits