[cfe-commits] r130381 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/Parser/MicrosoftExtensions.cpp

Francois Pichet pichet2000 at gmail.com
Wed Apr 27 22:14:50 PDT 2011


On Thu, Apr 28, 2011 at 12:53 AM, John McCall <rjmccall at apple.com> wrote:
>
> On Apr 27, 2011, at 9:39 PM, Francois Pichet wrote:
>
>> Author: fpichet
>> Date: Wed Apr 27 23:39:50 2011
>> New Revision: 130381
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=130381&view=rev
>> Log:
>> 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
>>
>> Modified:
>>    cfe/trunk/lib/Sema/SemaTemplate.cpp
>>    cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=130381&r1=130380&r2=130381&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Apr 27 23:39:50 2011
>> @@ -3093,6 +3093,15 @@
>>   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;
>> +    }
>> +
>
> You need to actually check for UO_AddrOf here.  I assume most unary operators don't work on the GUID type, but __extension__ does, and it's good to be future-proof.

yes clearly... that's what i wanted to do. thank for catching this.

> You should also make sure this works for reference template parameters;  maybe that never actually happens in the MFC headers, but it's good to get this right.
>

ok i'll think about that tomorrow. now i need to go sleep.




More information about the cfe-commits mailing list