On Wed, Feb 15, 2012 at 2:38 PM, Richard Smith <[email protected]> wrote: > Author: rsmith > Date: Wed Feb 15 16:38:09 2012 > New Revision: 150625 > > URL: http://llvm.org/viewvc/llvm-project?rev=150625&view=rev > Log: > Support GCC's bug^Wextension allowing class array members to be initalized by > a > parenthesized braced-init-list in the base/member initialization list. > > Modified: > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/include/clang/Sema/Initialization.h > cfe/trunk/lib/Sema/SemaInit.cpp > cfe/trunk/test/Misc/warning-flags.c > 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=150625&r1=150624&r2=150625&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 15 16:38:09 > 2012 > @@ -3550,7 +3550,10 @@ > "cannot initialize array of type %0 with non-constant array of type %1">; > def ext_array_init_copy : Extension< > "initialization of an array of type %0 from a compound literal of type %1 > is " > - "a GNU extension">; > + "a GNU extension">, InGroup<GNU>; > +def ext_array_init_parens : ExtWarn< > + "parenthesized initialization of a member array is a GNU extension">, > + InGroup<GNU>;
Can you put this in a more specific warning group, and make it DefaultError? Since only very new gcc versions accept this, we really want to discourage anyone from using it. -Eli > def warn_deprecated_string_literal_conversion : Warning< > "conversion from string literal to %0 is deprecated">, > InGroup<DeprecatedWritableStr>; > def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">; > > Modified: cfe/trunk/include/clang/Sema/Initialization.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=150625&r1=150624&r2=150625&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Sema/Initialization.h (original) > +++ cfe/trunk/include/clang/Sema/Initialization.h Wed Feb 15 16:38:09 2012 > @@ -592,6 +592,9 @@ > /// \brief Array initialization (from an array rvalue). > /// This is a GNU C extension. > SK_ArrayInit, > + /// \brief Array initialization from a parenthesized initializer list. > + /// This is a GNU C++ extension. > + SK_ParenthesizedArrayInit, > /// \brief Pass an object by indirect copy-and-restore. > SK_PassByIndirectCopyRestore, > /// \brief Pass an object by indirect restore. > @@ -912,6 +915,9 @@ > /// \brief Add an array initialization step. > void AddArrayInitStep(QualType T); > > + /// \brief Add a parenthesized array initialization step. > + void AddParenthesizedArrayInitStep(QualType T); > + > /// \brief Add a step to pass an object by indirect copy-restore. > void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy); > > > Modified: cfe/trunk/lib/Sema/SemaInit.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=150625&r1=150624&r2=150625&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaInit.cpp (original) > +++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Feb 15 16:38:09 2012 > @@ -2417,6 +2417,7 @@ > case SK_StringInit: > case SK_ObjCObjectConversion: > case SK_ArrayInit: > + case SK_ParenthesizedArrayInit: > case SK_PassByIndirectCopyRestore: > case SK_PassByIndirectRestore: > case SK_ProduceObjCObject: > @@ -2618,6 +2619,13 @@ > Steps.push_back(S); > } > > +void InitializationSequence::AddParenthesizedArrayInitStep(QualType T) { > + Step S; > + S.Kind = SK_ParenthesizedArrayInit; > + S.Type = T; > + Steps.push_back(S); > +} > + > void InitializationSequence::AddPassByIndirectCopyRestoreStep(QualType type, > bool > shouldCopy) { > Step s; > @@ -4058,6 +4066,15 @@ > else { > AddArrayInitStep(DestType); > } > + } > + // Note: as a GNU C++ extension, we allow initialization of a > + // class member from a parenthesized initializer list. > + else if (S.getLangOptions().CPlusPlus && > + Entity.getKind() == InitializedEntity::EK_Member && > + Initializer && isa<InitListExpr>(Initializer)) { > + TryListInitialization(S, Entity, Kind, cast<InitListExpr>(Initializer), > + *this); > + AddParenthesizedArrayInitStep(DestType); > } else if (DestAT->getElementType()->isAnyCharacterType()) > SetFailed(FK_ArrayNeedsInitListOrStringLiteral); > else > @@ -4787,6 +4804,7 @@ > case SK_StringInit: > case SK_ObjCObjectConversion: > case SK_ArrayInit: > + case SK_ParenthesizedArrayInit: > case SK_PassByIndirectCopyRestore: > case SK_PassByIndirectRestore: > case SK_ProduceObjCObject: > @@ -5213,6 +5231,13 @@ > } > break; > > + case SK_ParenthesizedArrayInit: > + // Okay: we checked everything before creating this step. Note that > + // this is a GNU extension. > + S.Diag(Kind.getLocation(), diag::ext_array_init_parens) > + << CurInit.get()->getSourceRange(); > + break; > + > case SK_PassByIndirectCopyRestore: > case SK_PassByIndirectRestore: > checkIndirectCopyRestoreSource(S, CurInit.get()); > @@ -5889,6 +5914,10 @@ > OS << "array initialization"; > break; > > + case SK_ParenthesizedArrayInit: > + OS << "parenthesized array initialization"; > + break; > + > case SK_PassByIndirectCopyRestore: > OS << "pass by indirect copy and restore"; > break; > > Modified: cfe/trunk/test/Misc/warning-flags.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=150625&r1=150624&r2=150625&view=diff > ============================================================================== > --- cfe/trunk/test/Misc/warning-flags.c (original) > +++ cfe/trunk/test/Misc/warning-flags.c Wed Feb 15 16:38:09 2012 > @@ -17,9 +17,8 @@ > > The list of warnings below should NEVER grow. It should gradually shrink to > 0. > > -CHECK: Warnings without flags (258): > +CHECK: Warnings without flags (257): > CHECK-NEXT: ext_anonymous_struct_union_qualified > -CHECK-NEXT: ext_array_init_copy > CHECK-NEXT: ext_binary_literal > CHECK-NEXT: ext_cast_fn_obj > CHECK-NEXT: ext_delete_void_ptr_operand > > 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=150625&r1=150624&r2=150625&view=diff > ============================================================================== > --- cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp (original) > +++ cfe/trunk/test/SemaCXX/cxx0x-initializer-aggregates.cpp Wed Feb 15 > 16:38:09 2012 > @@ -71,5 +71,5 @@ > static_assert(sizeof(overloaded({1})) == sizeof(one), "bad overload"); > } > > - struct C { int a[2]; C():a({1, 2}) { } }; // expected-error {{array > initializer must be an initializer list}} > + struct C { int a[2]; C():a({1, 2}) { } }; // expected-warning > {{parenthesized initialization of a member array is a GNU extension}} > } > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
