From: Aaron Ballman Date: Sun, 24 Nov 2013 21:35:16 +0000 (+0000) Subject: __declspec(uuid) is only supported for C++ code according to MSDN (as well as behavio... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa244b4c5df532f8220eeb1c3388fc28db4db6fa;p=clang __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 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index bf81169b7f..59a2c19a3a 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 1f78647153..4a8b528931 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 a6caf7acb8..e672d05d09 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;