From: Aaron Ballman Date: Sun, 24 Nov 2013 20:58:02 +0000 (+0000) Subject: __declspec(uuid) is only allowed on a class according to MSDN; this makes the semanti... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81e6d921275d44fc70f06904ea0785aca25512b7;p=clang __declspec(uuid) is only allowed on a class according to MSDN; this makes the semantic checking consistent with what the attribute specifies in Attr.td. Also adds a test case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195579 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 76cbaa297f..1f78647153 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4482,6 +4482,12 @@ static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { if (!checkMicrosoftExt(S, Attr, S.LangOpts.Borland)) return; + if (!isa(D)) { + S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) + << Attr.getName() << ExpectedClass; + return; + } + StringRef StrRef; SourceLocation LiteralLoc; if (!S.checkStringLiteralArgumentAttr(Attr, 0, StrRef, &LiteralLoc)) diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index efb5c3ce1f..8c1497a947 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -50,7 +50,7 @@ struct __declspec(uuid("0000000-0000-0000-1234-0000500000047")) uuid_attr_bad3 { struct __declspec(uuid("0000000-0000-0000-Z234-000000000047")) uuid_attr_bad4 { };// expected-error {{uuid attribute contains a malformed GUID}} struct __declspec(uuid("000000000000-0000-1234-000000000047")) uuid_attr_bad5 { };// expected-error {{uuid attribute contains a malformed GUID}} - +__declspec(uuid("000000A0-0000-0000-C000-000000000046")) int i; // expected-warning {{'uuid' attribute only applies to classes}} struct __declspec(uuid("000000A0-0000-0000-C000-000000000046")) struct_with_uuid { };