Allow IUnknown/IInterface types to come from extern C++
authorErich Keane <erich.keane@intel.com>
Tue, 26 Sep 2017 18:55:16 +0000 (18:55 +0000)
committerErich Keane <erich.keane@intel.com>
Tue, 26 Sep 2017 18:55:16 +0000 (18:55 +0000)
It was brought up in response to my last implementation for
this struct-as-interface features that at least 1 header in
the MS SDK uses "extern C++" around an IUnknown declaration.

The previous implementation demanded that this type exist
in the TranslationUnit DeclContext.  This small change simply
also allows in the situation where we're extern "C++".

llvm-svn: 314235

clang/lib/AST/DeclCXX.cpp
clang/test/SemaCXX/ms-iunknown.cpp

index d63d42c..e85ab41 100644 (file)
@@ -1491,7 +1491,8 @@ bool CXXRecordDecl::isInterfaceLike() const {
 
   // Check "Special" types.
   const auto *Uuid = getAttr<UuidAttr>();
-  if (Uuid && isStruct() && getDeclContext()->isTranslationUnit() &&
+  if (Uuid && isStruct() && (getDeclContext()->isTranslationUnit() ||
+                             getDeclContext()->isExternCXXContext()) &&
       ((getName() == "IUnknown" &&
         Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
        (getName() == "IDispatch" &&
index c965a4c..f73864d 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s 
 
-struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {
+extern "C++" struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {
   void foo();
 };
 struct IPropertyPageBase : public IUnknown {};