[PATCH] D37308: Interface class with uuid base record

Zahira Ammarguellat via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 30 12:51:17 PDT 2017


zahiraam created this revision.

Added support for interface inheriting from a uuid base record.


https://reviews.llvm.org/D37308

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/ms-uuid.cpp


Index: test/SemaCXX/ms-uuid.cpp
===================================================================
--- test/SemaCXX/ms-uuid.cpp
+++ test/SemaCXX/ms-uuid.cpp
@@ -93,3 +93,15 @@
 [uuid("000000A0-0000-0000-C000-000000000049"),
  uuid("000000A0-0000-0000-C000-000000000049")] class C10;
 }
+
+struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {};
+__interface ISfFileIOPropertyPage : public IUnknown {};
+
+class __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown1 {};
+__interface __declspec(dllimport) ISfFileIOPropertyPage1 : public IUnknown1 {}; // expected-error{{interface type cannot inherit from}}
+
+struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown2 {};
+__interface __declspec(dllimport) ISfFileIOPropertyPage2 : public IUnknown2 {}; // expected-error{{interface type cannot inherit from}}
+
+struct __declspec(dllexport) IUnknown3{};
+__interface foo : public IUnknown3{}; // expected-error{{interface type cannot inherit from}}
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -2398,6 +2398,13 @@
   }
 }
 
+
+/// \brief Tests if the __interface base is public.
+static bool IsBasePublicInterface(const CXXRecordDecl *RD,
+                                  AccessSpecifier spec) {
+  return RD->isInterface() && spec == AS_public;
+}
+
 /// \brief Performs the actual work of attaching the given base class
 /// specifiers to a C++ class.
 bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class,
@@ -2450,10 +2457,13 @@
       if (const RecordType *Record = NewBaseType->getAs<RecordType>()) {
         const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
         if (Class->isInterface() &&
-              (!RD->isInterface() ||
-               KnownBase->getAccessSpecifier() != AS_public)) {
-          // The Microsoft extension __interface does not permit bases that
-          // are not themselves public interfaces.
+            !IsBasePublicInterface(RD, KnownBase->getAccessSpecifier()) &&
+            // The Microsoft extension __interface does not permit bases that
+            // are not themselves public interfaces.
+            // An interface can inherit from a base, as long as it has
+            // uuid attributes.
+            (!RD->getAttr<UuidAttr>() ||
+	     Class->hasAttrs())) {
           Diag(KnownBase->getLocStart(), diag::err_invalid_base_in_interface)
             << getRecordDiagFromTagKind(RD->getTagKind()) << RD->getName()
             << RD->getSourceRange();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37308.113302.patch
Type: text/x-patch
Size: 2597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170830/dea4df12/attachment-0001.bin>


More information about the cfe-commits mailing list