__uuidof() and declspec(uuid("...")) should be allowed on enumeration types

Although not specifically mentioned in the documentation, MSVC accepts __uuidof(...) and declspec(uuid("...")) attributes on enumeration types in addition to structs/classes. This is meaningful, as such types *do* have associated UUIDs in ActiveX typelibs, and such attributes are included by default in the wrappers generated by their #import construct, so they are not particularly unusual.

clang currently rejects the declspec with a -Wignored-attributes warning, and errors on __uuidof() with "cannot call operator __uuidof on a type with no GUID" (because it rejected the uuid attribute, and therefore finds no value). This is causing problems for us while trying to use clang-tidy on a codebase that makes heavy use of ActiveX.

I believe I have found the relevant places to add this functionality, and attached are two patches adding this case to clang's implementation of these MS extensions.
enum-uuidof-master.patch against r285994 (or actually the git mirror 80464680ce)
enum-uuidof-39.patch is the same, but based on release_39@282636. I don't seriously think this warrants a backport to 3.9, though I wouldn't object :slight_smile: However, I prepared the patch for our own use in the meantime, so I might as well include it. They differ only due to some reformatting of the error messages in include/clang/Basic/DiagnosticSemaKinds.td.

Both include an update to test/Parser/MicrosoftExtensions.cpp to exercise the new functionality.

This is my first time contributing to LLVM, so if I've missed anything else needed to prepare this for review just let me know!

__uuidof: __uuidof Operator | Microsoft Docs
declspec(uuid("...")): uuid (C++) | Microsoft Docs
#import: #import directive (C++) | Microsoft Docs

enum-uuidof-39.patch (4.22 KB)

enum-uuidof-master.patch (4.16 KB)

Although not specifically mentioned in the documentation, MSVC accepts
__uuidof(...) and declspec(uuid("...")) attributes on enumeration types in
addition to structs/classes. This is meaningful, as such types *do* have
associated UUIDs in ActiveX typelibs, and such attributes are included by
default in the wrappers generated by their #import construct, so they are
not particularly unusual.

clang currently rejects the declspec with a -Wignored-attributes warning,
and errors on __uuidof() with "cannot call operator __uuidof on a type with
no GUID" (because it rejected the uuid attribute, and therefore finds no
value). This is causing problems for us while trying to use clang-tidy on a
codebase that makes heavy use of ActiveX.

I believe I have found the relevant places to add this functionality, and
attached are two patches adding this case to clang's implementation of
these MS extensions.
enum-uuidof-master.patch against r285994 (or actually the git mirror
80464680ce)
enum-uuidof-39.patch is the same, but based on release_39@282636. I don't
seriously think this warrants a backport to 3.9, though I wouldn't object
:slight_smile: However, I prepared the patch for our own use in the meantime, so I
might as well include it. They differ only due to some reformatting of the
error messages in include/clang/Basic/DiagnosticSemaKinds.td.

Both include an update to test/Parser/MicrosoftExtensions.cpp to exercise
the new functionality.

This is my first time contributing to LLVM, so if I've missed anything
else needed to prepare this for review just let me know!

I'd appreciate it if you could create a differential on phabricator:
http://llvm.org/docs/Phabricator.html

Thanks!

I'd appreciate it if you could create a differential on phabricator: http://llvm.org/docs/Phabricator.html

Ok, if I did this right: https://reviews.llvm.org/D26846

Thanks!

From: David Majnemer [mailto:david.majnemer@gmail.com]
Sent: Thursday, November 17, 2016 11:41 PM

I'd appreciate it if you could create a differential on phabricator: http://llvm.org/docs/Phabricator.html

Ok, if I did this right: https://reviews.llvm.org/D26846

Thanks!

You're welcome!