From aa244b4c5df532f8220eeb1c3388fc28db4db6fa Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron@aaronballman.com>
Date: Sun, 24 Nov 2013 21:35:16 +0000
Subject: [PATCH] __declspec(uuid) is only supported for C++ code according to
 MSDN (as well as behaviorally in MSVC). This adds a generic diagnostic that
 we use for uuid, and can use for some other attributes as well, and adds a
 testcase.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195580 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 lib/Sema/SemaDeclAttr.cpp                  | 14 ++++++++++++++
 test/Sema/MicrosoftExtensions.c            |  5 +----
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index bf81169b7f8..59a2c19a3a3 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2385,6 +2385,8 @@ def err_attribute_regparm_wrong_platform : Error<
   "'regparm' is not valid on this platform">;
 def err_attribute_regparm_invalid_number : Error<
   "'regparm' parameter must be between 0 and %0 inclusive">;
+def err_attribute_not_supported_in_lang : Error<
+  "%0 attribute is not supported in %select{C|C++|Objective-C}1">;
 
 
 // Clang-Specific Attributes
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 1f786471537..4a8b5289317 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -61,6 +61,14 @@ enum AttributeDeclKind {
   ExpectedType
 };
 
+namespace AttributeLangSupport {
+  enum {
+    C,
+    Cpp,
+    ObjC
+  };
+}
+
 //===----------------------------------------------------------------------===//
 //  Helper functions
 //===----------------------------------------------------------------------===//
@@ -4479,6 +4487,12 @@ static bool checkMicrosoftExt(Sema &S, const AttributeList &Attr,
 }
 
 static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  if (!S.LangOpts.CPlusPlus) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_in_lang)
+      << Attr.getName() << AttributeLangSupport::C;
+    return;
+  }
+
   if (!checkMicrosoftExt(S, Attr, S.LangOpts.Borland))
     return;
 
diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c
index a6caf7acb8a..e672d05d090 100644
--- a/test/Sema/MicrosoftExtensions.c
+++ b/test/Sema/MicrosoftExtensions.c
@@ -20,10 +20,7 @@ struct D {
    int D[];
 };
 
-
-
-
-
+struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */
 
 typedef struct notnested {
   long bad1;
-- 
GitLab