]> granicus.if.org Git - clang/commitdiff
Friends cannot be declared module-private
authorDouglas Gregor <dgregor@apple.com>
Fri, 9 Sep 2011 21:14:29 +0000 (21:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 9 Sep 2011 21:14:29 +0000 (21:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139411 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Sema/DeclSpec.cpp
test/Modules/module-private.cpp

index 0f3b998c6533cb2ff4f2548f8ffea754979c6bdc..2c8a566719eb44065206457ee2d9273798412bcc 100644 (file)
@@ -582,6 +582,8 @@ def err_module_expected_ident : Error<
   "expected a module name after '__import_module__'">;
 def err_module_expected_semi : Error<
   "expected a semicolon name after module name">;
+def err_module_private_friend : Error<
+  "friend cannot be declared __module_private__">;
 }
 
 } // end of Parser diagnostics
index 55964d50062e653723884371aabb161ee5a49e05..531e7a535a3dd6e4b9b1b24a9d5369e6c336d121 100644 (file)
@@ -899,8 +899,15 @@ void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) {
     ClearStorageClassSpecs();
   }
 
-  assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
+  // A friend cannot be specified as module-private.
+  if (isFriendSpecified() && isModulePrivateSpecified()) {
+    Diag(D, ModulePrivateLoc, diag::err_module_private_friend)
+      << FixItHint::CreateRemoval(ModulePrivateLoc);
+    ModulePrivateLoc = SourceLocation();
+  }
 
+  assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
   // Okay, now we can infer the real type.
 
   // TODO: return "auto function" and other bad things based on the real type.
index 0f1d5923dc4f0f545695a47012dabf64d2023422..849897f7333dff6c028e81ff35ff206dac1ce4d0 100644 (file)
@@ -95,6 +95,9 @@ template<typename T>
 struct public_class {
   struct inner_struct;
   static int static_var;
+
+  friend __module_private__ void public_func(); // expected-error{{friend cannot be declared __module_private__}}
+  friend __module_private__ struct public_struct; // expected-error{{friend cannot be declared __module_private__}}
 };
 
 template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}