[cfe-dev] [ms-mode] Delayed parsing for a UnaryExprOrTypeTraitExpr?

Richard Smith richard at metafoo.co.uk
Mon Jun 17 11:14:01 PDT 2013


On Mon, Jun 17, 2013 at 1:36 AM, Will Wilson <will at indefiant.com> wrote:
> Hi All,
>
> I've been attempting to find a clean way of dealing with an issue parsing
> the core MS ATL headers in clang. The issue is a missing typename keyword in
> a sizeof expression containing a dependent name in the header atlstr.h.
> Annoyingly, this is the last error I'm encountering in the core MS headers.
>
> A simplified example is:
>
> template <class T>
> size_t GetSize() {
> return sizeof(T::SubType); // Should have typename keyword
> }
>
> struct TestStruct {
> typedef int SubType;
> };
>
> void test_typename_missing_msext() {
> GetSize<TestStruct>();
> }
>
>
> This passes in MSVC as it leaves almost all template evaluation until
> instantiation by which time it can deduce if T::SubType refers to a typename
> or a static member.
>
> Clang does the right thing and relies on the typename keyword to decide
> before institution whether the dependent expression refers to a type or a
> non-type member. Of note, clang already supports (with warnings) parsing
> dependent names missing the typename keyword - but only in locations where
> only a type is permitted (as implemented by Francois in r129425). The
> problem is dealing with a sizeof expression where the ambiguity cannot be
> resolved until instantiation.
>
> So, in short are there any safe approaches I could take with this (with a
> view to patching clang)? From my perspective it looks like there needs to be
> a third "delayed evaluation" state for UnaryExprOrTypeTraitExpr in order to
> support MicrosoftMode correctly. Or even a new
> DelayedUnaryExprOrTypeTraitExpr for MicrosoftMode. Does this sound
> reasonable or is there a better approach?

I suggest that when transforming a UnaryExprOrTypeTraitExpr, you look
for the case where the operand is a ParenExpr containing a
DependentScopeDeclRefExpr, perform the lookup into the dependent
scope, and if it resolves to a type then produce that type (and a
warning in MS mode / error outside MS mode).



More information about the cfe-dev mailing list