From 81e6d921275d44fc70f06904ea0785aca25512b7 Mon Sep 17 00:00:00 2001 From: Aaron Ballman <aaron@aaronballman.com> Date: Sun, 24 Nov 2013 20:58:02 +0000 Subject: [PATCH] __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 --- lib/Sema/SemaDeclAttr.cpp | 6 ++++++ test/Parser/MicrosoftExtensions.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 76cbaa297f1..1f786471537 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<CXXRecordDecl>(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 efb5c3ce1fd..8c1497a9472 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 { }; -- GitLab