r196892 - Implement DR1460: fix handling of default initializers in unions; don't allow

Richard Smith richard at metafoo.co.uk
Tue Dec 10 13:01:08 PST 2013


On Tue, Dec 10, 2013 at 12:50 PM, David Blaikie <dblaikie at gmail.com> wrote:

> On Tue, Dec 10, 2013 at 12:25 AM, Richard Smith
> <richard-llvm at metafoo.co.uk> wrote:
> > Author: rsmith
> > Date: Tue Dec 10 02:25:00 2013
> > New Revision: 196892
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=196892&view=rev
> > Log:
> > Implement DR1460: fix handling of default initializers in unions; don't
> allow
> > more than one such initializer in a union, make mem-initializers override
> > default initializers for other union members, handle anonymous unions
> with
> > anonymous struct members better. Fix a couple of semi-related bugs
> exposed by
> > the tests for same.
> >
> > Added:
> >     cfe/trunk/test/CXX/class/class.union/p8.cpp
> >     cfe/trunk/test/CXX/drs/dr14xx.cpp
> > Modified:
> >     cfe/trunk/include/clang/AST/DeclCXX.h
> >     cfe/trunk/lib/AST/ASTImporter.cpp
> >     cfe/trunk/lib/AST/DeclCXX.cpp
> >     cfe/trunk/lib/Sema/SemaDecl.cpp
> >     cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> >     cfe/trunk/lib/Sema/SemaExpr.cpp
> >     cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> >     cfe/trunk/lib/Serialization/ASTWriter.cpp
> >     cfe/trunk/test/CXX/special/class.init/class.base.init/p8-0x.cpp
> >     cfe/trunk/test/CodeGenCXX/member-init-anon-union.cpp
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=196892&r1=196891&r2=196892&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Dec 10 02:25:00 2013
> > @@ -3320,6 +3331,7 @@ struct BaseAndFieldInfo {
> >    ImplicitInitializerKind IIK;
> >    llvm::DenseMap<const void *, CXXCtorInitializer*> AllBaseFields;
> >    SmallVector<CXXCtorInitializer*, 8> AllToInit;
> > +  llvm::DenseMap<TagDecl*, FieldDecl*> ActiveUnionMember;
> >
> >    BaseAndFieldInfo(Sema &S, CXXConstructorDecl *Ctor, bool
> ErrorsInInits)
> >      : S(S), Ctor(Ctor), AnyErrorsInInits(ErrorsInInits) {
> > @@ -3357,20 +3369,50 @@ struct BaseAndFieldInfo {
> >
> >      return false;
> >    }
> > -};
> > -}
> >
> > -/// \brief Determine whether the given indirect field declaration is
> somewhere
> > -/// within an anonymous union.
> > -static bool isWithinAnonymousUnion(IndirectFieldDecl *F) {
> > -  for (IndirectFieldDecl::chain_iterator C = F->chain_begin(),
> > -                                      CEnd = F->chain_end();
> > -       C != CEnd; ++C)
> > -    if (CXXRecordDecl *Record =
> dyn_cast<CXXRecordDecl>((*C)->getDeclContext()))
> > -      if (Record->isUnion())
> > +  bool isInactiveUnionMember(FieldDecl *Field) {
> > +    RecordDecl *Record = Field->getParent();
> > +    if (!Record->isUnion())
> > +      return false;
> > +
> > +    FieldDecl *Active =
> ActiveUnionMember.lookup(Record->getCanonicalDecl());
> > +    if (Active)
>
> Collapse the initialization into the conditional here?


Sounds good, r196959.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131210/28a6b012/attachment.html>


More information about the cfe-commits mailing list