woboq / verdigris

Qt without moc: set of macros to use Qt without needing moc
https://woboq.com/blog/verdigris-qt-without-moc.html
GNU Lesser General Public License v3.0
643 stars 60 forks source link

Constexpr state potentially ill-formed for templated classes #73

Closed fiesh closed 5 years ago

fiesh commented 5 years ago

After implementing code following the constexpr-state trick guide from

https://woboq.com/blog/verdigris-implementation-tricks.html

I ran into https://bugs.llvm.org/show_bug.cgi?id=41785

However, as explained there, it's actually not a compiler bug but an ill-formed program. It seems to me that the "friend-trick" used in verdigris does not change this but just happens to work with compilers despite technically also being ill-formed code.

ogoffart commented 5 years ago

you might be right. :-/ However maybe the fact that the friend function has a a parameter of that class type might change that.

That said, i don't fully understand the issue, since the names should still refer to the same declarations while.

fiesh commented 5 years ago

I don't see how the first parameter could change that given that it's the same for all function declarations :-(

fiesh commented 5 years ago

Maybe using __COUNTER__ (or potentially BOOST_PP_COUNTER for compilers that don't have __COUNTER__, if they exist) might make it possible to handle the templated case?

ogoffart commented 5 years ago

Note that the version 1.2 of verdigris does not use exactly the method described in the blog post anymore. It uses __COUNTER__ do disambiguate, so maybe the problem is actually solved.

fiesh commented 5 years ago

Oh, it already does! I had no idea.

I think this should be fine. W_STATE_APPEND and W_STATE_APPEND_NS do not refer to return types of member functions at all, so I think there's no way the problem is triggered.

So I believe this issue can be closed.

ogoffart commented 5 years ago

Thanks for the feedback.

crazybie commented 4 years ago

Note that the version 1.2 of verdigris does not use exactly the method described in the blog post anymore. It uses __COUNTER__ do disambiguate, so maybe the problem is actually solved.

but can you explain the new method a bit because the source code is hard to undersand, thanks.