diff options
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index cef4870638..c566b236e4 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -170,6 +170,7 @@ class InitListChecker { Sema &SemaRef; bool hadError; bool VerifyOnly; // no diagnostics, no structure building + bool AllowBraceElision; std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic; InitListExpr *FullyStructuredList; @@ -260,7 +261,8 @@ class InitListChecker { public: InitListChecker(Sema &S, const InitializedEntity &Entity, - InitListExpr *IL, QualType &T, bool VerifyOnly); + InitListExpr *IL, QualType &T, bool VerifyOnly, + bool AllowBraceElision); bool HadError() { return hadError; } // @brief Retrieves the fully-structured initializer list used for @@ -466,8 +468,8 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity, InitListChecker::InitListChecker(Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, - bool VerifyOnly) - : SemaRef(S), VerifyOnly(VerifyOnly) { + bool VerifyOnly, bool AllowBraceElision) + : SemaRef(S), VerifyOnly(VerifyOnly), AllowBraceElision(AllowBraceElision) { hadError = false; unsigned newIndex = 0; @@ -551,10 +553,14 @@ void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity, /*SubobjectIsDesignatorContext=*/false, Index, StructuredSubobjectInitList, StructuredSubobjectInitIndex); - unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1); - if (!VerifyOnly) { + + if (VerifyOnly) { + if (!AllowBraceElision && (T->isArrayType() || T->isRecordType())) + hadError = true; + } else { StructuredSubobjectInitList->setType(T); + unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1); // Update the structured sub-object initializer so that it's ending // range corresponds with the end of the last initializer it used. if (EndIndex < ParentIList->getNumInits()) { @@ -563,10 +569,11 @@ void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity, StructuredSubobjectInitList->setRBraceLoc(EndLoc); } - // Warn about missing braces. + // Complain about missing braces. if (T->isArrayType() || T->isRecordType()) { SemaRef.Diag(StructuredSubobjectInitList->getLocStart(), - diag::warn_missing_braces) + AllowBraceElision ? diag::warn_missing_braces : + diag::err_missing_braces) << StructuredSubobjectInitList->getSourceRange() << FixItHint::CreateInsertion( StructuredSubobjectInitList->getLocStart(), "{") @@ -574,6 +581,8 @@ void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity, SemaRef.PP.getLocForEndOfToken( StructuredSubobjectInitList->getLocEnd()), "}"); + if (!AllowBraceElision) + hadError = true; } } } @@ -2808,7 +2817,9 @@ static void TryListInitialization(Sema &S, } InitListChecker CheckInitList(S, Entity, InitList, - DestType, /*VerifyOnly=*/true); + DestType, /*VerifyOnly=*/true, + Kind.getKind() != InitializationKind::IK_Direct || + !S.getLangOptions().CPlusPlus0x); if (CheckInitList.HadError()) { Sequence.SetFailed(InitializationSequence::FK_ListInitializationFailed); return; @@ -4654,7 +4665,9 @@ InitializationSequence::Perform(Sema &S, InitListExpr *InitList = cast<InitListExpr>(CurInit.get()); QualType Ty = Step->Type; InitListChecker PerformInitList(S, Entity, InitList, - ResultType ? *ResultType : Ty, /*VerifyOnly=*/false); + ResultType ? *ResultType : Ty, /*VerifyOnly=*/false, + Kind.getKind() != InitializationKind::IK_Direct || + !S.getLangOptions().CPlusPlus0x); if (PerformInitList.HadError()) return ExprError(); @@ -5180,7 +5193,9 @@ bool InitializationSequence::Diagnose(Sema &S, InitListExpr* InitList = cast<InitListExpr>(Args[0]); QualType DestType = Entity.getType(); InitListChecker DiagnoseInitList(S, Entity, InitList, - DestType, /*VerifyOnly=*/false); + DestType, /*VerifyOnly=*/false, + Kind.getKind() != InitializationKind::IK_Direct || + !S.getLangOptions().CPlusPlus0x); assert(DiagnoseInitList.HadError() && "Inconsistent init list check result."); break; |