r183397 - Implement DR1270: braces can be elided in all aggregate initialization, not
Richard Smith
richard-llvm at metafoo.co.uk
Thu Jun 6 04:41:06 PDT 2013
Author: rsmith
Date: Thu Jun 6 06:41:05 2013
New Revision: 183397
URL: http://llvm.org/viewvc/llvm-project?rev=183397&view=rev
Log:
Implement DR1270: braces can be elided in all aggregate initialization, not
just copy-list-initialization in a variable declaration. This effectively
reverts r142147.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=183397&r1=183396&r2=183397&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun 6 06:41:05 2013
@@ -3703,9 +3703,6 @@ def warn_anon_bitfield_width_exceeds_typ
def warn_missing_braces : Warning<
"suggest braces around initialization of subobject">,
InGroup<MissingBraces>, DefaultIgnore;
-def err_missing_braces : Error<
- "cannot omit braces around initialization of subobject when using direct "
- "list-initialization">;
def err_redefinition_of_label : Error<"redefinition of label %0">;
def err_undeclared_label_use : Error<"use of undeclared label %0">;
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=183397&r1=183396&r2=183397&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Jun 6 06:41:05 2013
@@ -236,7 +236,6 @@ class InitListChecker {
Sema &SemaRef;
bool hadError;
bool VerifyOnly; // no diagnostics, no structure building
- bool AllowBraceElision;
llvm::DenseMap<InitListExpr *, InitListExpr *> SyntacticToSemantic;
InitListExpr *FullyStructuredList;
@@ -327,8 +326,7 @@ class InitListChecker {
public:
InitListChecker(Sema &S, const InitializedEntity &Entity,
- InitListExpr *IL, QualType &T, bool VerifyOnly,
- bool AllowBraceElision);
+ InitListExpr *IL, QualType &T, bool VerifyOnly);
bool HadError() { return hadError; }
// @brief Retrieves the fully-structured initializer list used for
@@ -559,8 +557,8 @@ InitListChecker::FillInValueInitializati
InitListChecker::InitListChecker(Sema &S, const InitializedEntity &Entity,
InitListExpr *IL, QualType &T,
- bool VerifyOnly, bool AllowBraceElision)
- : SemaRef(S), VerifyOnly(VerifyOnly), AllowBraceElision(AllowBraceElision) {
+ bool VerifyOnly)
+ : SemaRef(S), VerifyOnly(VerifyOnly) {
hadError = false;
unsigned newIndex = 0;
@@ -645,10 +643,7 @@ void InitListChecker::CheckImplicitInitL
StructuredSubobjectInitList,
StructuredSubobjectInitIndex);
- if (VerifyOnly) {
- if (!AllowBraceElision && (T->isArrayType() || T->isRecordType()))
- hadError = true;
- } else {
+ if (!VerifyOnly) {
StructuredSubobjectInitList->setType(T);
unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
@@ -663,8 +658,7 @@ void InitListChecker::CheckImplicitInitL
// Complain about missing braces.
if (T->isArrayType() || T->isRecordType()) {
SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
- AllowBraceElision ? diag::warn_missing_braces :
- diag::err_missing_braces)
+ diag::warn_missing_braces)
<< StructuredSubobjectInitList->getSourceRange()
<< FixItHint::CreateInsertion(
StructuredSubobjectInitList->getLocStart(), "{")
@@ -672,8 +666,6 @@ void InitListChecker::CheckImplicitInitL
SemaRef.PP.getLocForEndOfToken(
StructuredSubobjectInitList->getLocEnd()),
"}");
- if (!AllowBraceElision)
- hadError = true;
}
}
}
@@ -3277,9 +3269,7 @@ static void TryListInitialization(Sema &
}
InitListChecker CheckInitList(S, Entity, InitList,
- DestType, /*VerifyOnly=*/true,
- Kind.getKind() != InitializationKind::IK_DirectList ||
- !S.getLangOpts().CPlusPlus11);
+ DestType, /*VerifyOnly=*/true);
if (CheckInitList.HadError()) {
Sequence.SetFailed(InitializationSequence::FK_ListInitializationFailed);
return;
@@ -5695,9 +5685,7 @@ InitializationSequence::Perform(Sema &S,
InitializedEntity TempEntity = InitializedEntity::InitializeTemporary(Ty);
InitializedEntity InitEntity = IsTemporary ? TempEntity : Entity;
InitListChecker PerformInitList(S, InitEntity,
- InitList, Ty, /*VerifyOnly=*/false,
- Kind.getKind() != InitializationKind::IK_DirectList ||
- !S.getLangOpts().CPlusPlus11);
+ InitList, Ty, /*VerifyOnly=*/false);
if (PerformInitList.HadError())
return ExprError();
@@ -6381,9 +6369,7 @@ bool InitializationSequence::Diagnose(Se
InitListExpr* InitList = cast<InitListExpr>(Args[0]);
QualType DestType = Entity.getType();
InitListChecker DiagnoseInitList(S, Entity, InitList,
- DestType, /*VerifyOnly=*/false,
- Kind.getKind() != InitializationKind::IK_DirectList ||
- !S.getLangOpts().CPlusPlus11);
+ DestType, /*VerifyOnly=*/false);
assert(DiagnoseInitList.HadError() &&
"Inconsistent init list check result.");
break;
Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp?rev=183397&r1=183396&r2=183397&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp Thu Jun 6 06:41:05 2013
@@ -4,7 +4,6 @@ struct one { char c[1]; };
struct two { char c[2]; };
namespace aggregate {
- // Direct list initialization does NOT allow braces to be elided!
struct S {
int ar[2];
struct T {
@@ -20,25 +19,25 @@ namespace aggregate {
};
void bracing() {
- S s1 = { 1, 2, 3 ,4, 5, 6, 7, 8 }; // no-error
- S s2{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } }; // completely braced
- S s3{ 1, 2, 3, 4, 5, 6 }; // expected-error 5 {{cannot omit braces}}
- S s4{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } }; // expected-error 2 {{cannot omit braces}}
- S s5{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} }; // expected-error {{cannot omit braces}}
+ S s1 = { 1, 2, 3 ,4, 5, 6, 7, 8 };
+ S s2{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } };
+ S s3{ 1, 2, 3, 4, 5, 6 };
+ S s4{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } };
+ S s5{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} };
}
void bracing_new() {
- new S{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } }; // completely braced
- new S{ 1, 2, 3, 4, 5, 6 }; // expected-error 5 {{cannot omit braces}}
- new S{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } }; // expected-error 2 {{cannot omit braces}}
- new S{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} }; // expected-error {{cannot omit braces}}
+ new S{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } };
+ new S{ 1, 2, 3, 4, 5, 6 };
+ new S{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } };
+ new S{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} };
}
void bracing_construct() {
- (void) S{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } }; // completely braced
- (void) S{ 1, 2, 3, 4, 5, 6 }; // expected-error 5 {{cannot omit braces}}
- (void) S{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } }; // expected-error 2 {{cannot omit braces}}
- (void) S{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} }; // expected-error {{cannot omit braces}}
+ (void) S{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } };
+ (void) S{ 1, 2, 3, 4, 5, 6 };
+ (void) S{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } };
+ (void) S{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} };
}
struct String {
More information about the cfe-commits
mailing list