diff options
author | Francois Pichet <pichet2000@gmail.com> | 2011-04-28 04:39:50 +0000 |
---|---|---|
committer | Francois Pichet <pichet2000@gmail.com> | 2011-04-28 04:39:50 +0000 |
commit | a1c1352a36d4f2718cb6d4fbbb3d3ced0d113bb9 (patch) | |
tree | cae3bd00b131ca6577295e367b3653a880f39861 | |
parent | 21735e608df5c0a028bc3f121e7e89113328f992 (diff) | |
download | bcm5719-llvm-a1c1352a36d4f2718cb6d4fbbb3d3ced0d113bb9.tar.gz bcm5719-llvm-a1c1352a36d4f2718cb6d4fbbb3d3ced0d113bb9.zip |
Support &__uuidof(type) as a non type template argument.
This idiom is used everywhere in MFC/COM code and as such this patch removes hundreds of errors when parsing MFC code with clang.
Example:
template <class T, const GUID* g = &__uuidof(T)>
class ComTemplate { };
typedef ComTemplate<struct_with_uuid, &__uuidof(struct_with_uuid)> COM_TYPE;
Of course this is just parsing support. Trying to use this in CodeGen will generate:
error: cannot yet mangle expression type CXXUuidofExpr
llvm-svn: 130381
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 9 | ||||
-rw-r--r-- | clang/test/Parser/MicrosoftExtensions.cpp | 7 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 3deeedc90da..ae80181d849 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -3093,6 +3093,15 @@ CheckTemplateArgumentAddressOfObjectOrFunction(Sema &S, bool AddressTaken = false; SourceLocation AddrOpLoc; if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(Arg)) { + + // Support &__uuidof(class_with_uuid) as a non-type template argument. + // Very common in Microsoft COM headers. + if (S.getLangOptions().Microsoft && + isa<CXXUuidofExpr>(UnOp->getSubExpr())) { + Converted = TemplateArgument(ArgIn); + return false; + } + if (UnOp->getOpcode() == UO_AddrOf) { DRE = dyn_cast<DeclRefExpr>(UnOp->getSubExpr()); AddressTaken = true; diff --git a/clang/test/Parser/MicrosoftExtensions.cpp b/clang/test/Parser/MicrosoftExtensions.cpp index a5d2d513b12..decd57510f5 100644 --- a/clang/test/Parser/MicrosoftExtensions.cpp +++ b/clang/test/Parser/MicrosoftExtensions.cpp @@ -95,6 +95,13 @@ void template_uuid() } +template <class T, const GUID* g = &__uuidof(T)> +class COM_CLASS_TEMPLATE { }; + +typedef COM_CLASS_TEMPLATE<struct_with_uuid, &__uuidof(struct_with_uuid)> COM_TYPE_1; +typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2; + + class CtorCall { public: |