taocpp / PEGTL

Parsing Expression Grammar Template Library
Boost Software License 1.0
1.94k stars 228 forks source link

Compilation issue with Visual Studio 2015 CTP #2

Closed samhocevar closed 9 years ago

samhocevar commented 9 years ago

The VS2015 technology preview is the only version that almost manages to build PEGTL. However, it fails to understand the decltype+comma SFINAE trick in rule_match_call.hh:

1>c:\users\sam\pegtl\pegtl\internal\rule_match_call.hh(26): error C2535: 'unknown-type
    pegtl::internal::rule_match_call<Rule,E,Action,Control>::match(Input &,States &&...)':
    member function already defined or declared
1>c:\users\sam\pegtl\pegtl\internal\rule_match_call.hh(17): note: see declaration of
    'pegtl::internal::rule_match_call<Rule,E,Action,Control>::match'
1>c:\users\sam\pegtl\pegtl\internal\rule_match_call.hh(27): note: see reference to class
    template instantiation 'pegtl::internal::rule_match_call<Rule,E,Action,Control>' being
    compiled

Even though this is a compiler bug, do you think a workaround is possible? I have tried a few things but failed to come up with something that works.

d-frey commented 9 years ago

Please report a bug against Visual C++ if you haven't done so already.

As a work-around, please try to include <type_traits> and use

typename std::enable_if< sizeof( Rule::template match< E, Action, Control >( in, st ... ) ) != 0, bool >::type

as the first trailing return type and

typename std::enable_if< sizeof( Rule::match( in ) ) != 0, bool >::type

for the second. If that helps, I'd be willing to change the code to this uncool version :)

If it doesn't help, I can't do much as I don't have Visual C++. Of course, if you can come up with some other reasonable work-around, we'll look into it.

samhocevar commented 9 years ago

I have created a minimal test case and posted a bug report to Microsoft. I only have limited access to a Windows computer so I haven’t yet found a workaround. I will try your suggestion though, but I seem to remember trying something like that and it didn’t work because of sizeof actually returning a fatal error.

Note by the way that if you have access to Windows, the Visual Studio technology previews can be downloaded freely.

d-frey commented 9 years ago

I don't have Windows, so the free download of Visual Studio won't help me.

For now, I'm closing this issue as the bug is in the compiler of VS, not in our code. If you can come up with a viable work-around, please don't hesitate to let us know about it.

d-frey commented 9 years ago

Sam,

can you please try to add a defaulted dummy template parameter to the second overload? Like this:

template< typename Input, typename ... States, int = 0 >
static auto match( Input & in, States && ... ) -> decltype( Rule::match( in ), bool() )
...

(but note: Just for the second overload!)

Thanks in advance!

samhocevar commented 9 years ago

Ah that’s clever! It did the trick, thanks.

d-frey commented 9 years ago

Work-around committed.