diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/MicrosoftCXXABI.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 54 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 8 |
3 files changed, 52 insertions, 20 deletions
diff --git a/clang/lib/AST/MicrosoftCXXABI.cpp b/clang/lib/AST/MicrosoftCXXABI.cpp index 51308ea0c0f..575272d3573 100644 --- a/clang/lib/AST/MicrosoftCXXABI.cpp +++ b/clang/lib/AST/MicrosoftCXXABI.cpp @@ -55,6 +55,16 @@ public: unsigned MicrosoftCXXABI::getMemberPointerSize(const MemberPointerType *MPT) const { QualType Pointee = MPT->getPointeeType(); CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl(); + + if (RD->getTypeForDecl()->isIncompleteType()) { + if (RD->hasAttr<SingleInheritanceAttr>()) + return 1; + else if (RD->hasAttr<MultipleInheritanceAttr>()) + return 2; + else + return 3; + } + if (RD->getNumVBases() > 0) { if (Pointee->isFunctionType()) return 3; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 50d11175995..bf1c14338db 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -4149,20 +4149,50 @@ static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "uuid"; } +static bool hasOtherInheritanceAttr(Decl *D, AttributeList::Kind Kind, + int& Existing) { + if (Kind != AttributeList::AT_SingleInheritance && + D->hasAttr<SingleInheritanceAttr>()) { + Existing = 0; + return true; + } + else if (Kind != AttributeList::AT_MultipleInheritance && + D->hasAttr<MultipleInheritanceAttr>()) { + Existing = 1; + return true; + } + else if (Kind != AttributeList::AT_VirtualInheritance && + D->hasAttr<VirtualInheritanceAttr>()) { + Existing = 2; + return true; + } + return false; +} + static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (S.LangOpts.MicrosoftExt) { - AttributeList::Kind Kind = Attr.getKind(); - if (Kind == AttributeList::AT_SingleInheritance) - D->addAttr( - ::new (S.Context) SingleInheritanceAttr(Attr.getRange(), S.Context)); - else if (Kind == AttributeList::AT_MultipleInheritance) - D->addAttr( - ::new (S.Context) MultipleInheritanceAttr(Attr.getRange(), S.Context)); - else if (Kind == AttributeList::AT_VirtualInheritance) - D->addAttr( - ::new (S.Context) VirtualInheritanceAttr(Attr.getRange(), S.Context)); - } else + if (!S.LangOpts.MicrosoftExt) { S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName(); + return; + } + + AttributeList::Kind Kind = Attr.getKind(); + + int Existing; + if (hasOtherInheritanceAttr(D->getCanonicalDecl(), Kind, Existing)) { + S.Diag(Attr.getLoc(), diag::warn_ms_inheritance_already_declared) << Existing; + return; + } + + if (Kind == AttributeList::AT_SingleInheritance) { + D->addAttr( + ::new (S.Context) SingleInheritanceAttr(Attr.getRange(), S.Context)); + } else if (Kind == AttributeList::AT_MultipleInheritance) { + D->addAttr( + ::new (S.Context) MultipleInheritanceAttr(Attr.getRange(), S.Context)); + } else if (Kind == AttributeList::AT_VirtualInheritance) { + D->addAttr( + ::new (S.Context) VirtualInheritanceAttr(Attr.getRange(), S.Context)); + } } static void handlePortabilityAttr(Sema &S, Decl *D, const AttributeList &Attr) { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 82dccfa5f44..68cd5cdcf83 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1583,14 +1583,6 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class, return QualType(); } - // In the Microsoft ABI, the class is allowed to be an incomplete - // type. In such cases, the compiler makes a worst-case assumption. - // We make no such assumption right now, so emit an error if the - // class isn't a complete type. - if (Context.getTargetInfo().getCXXABI() == CXXABI_Microsoft && - RequireCompleteType(Loc, Class, diag::err_incomplete_type)) - return QualType(); - return Context.getMemberPointerType(T, Class.getTypePtr()); } |

