mp-units icon indicating copy to clipboard operation
mp-units copied to clipboard

refactor: apply TODOs about MSVC and lambdas in unevaluated contexts

Open JohelEGP opened this issue 3 years ago • 18 comments

According to https://en.cppreference.com/w/cpp/compiler_support, MSVC now supports them. https://godbolt.org/z/dfc3ro. bits/basic_concepts.h has one such TODO.

JohelEGP avatar Jan 18 '21 22:01 JohelEGP

I should note that Clang 12 did not implement this. If this were to be applied, we won't be able to support Clang 12. Otherwise, it seems all we'd have to do is make TYPENAME expand to typename, as done for MSVC. And then work out any bugs that pop up.

JohelEGP avatar Feb 20 '21 17:02 JohelEGP

According to https://en.cppreference.com/w/cpp/compiler_support, MSVC now supports them. https://godbolt.org/z/dfc3ro. bits/basic_concepts.h has one such TODO.

As I am aware of for MSVC it is only supported in some Preview version and not in an officially released version? At least it does not work for me on an updated VS2019.

mpusz avatar Feb 20 '21 23:02 mpusz

I have all of the changes ready for CLang support for a long time now. However, clang has some major issues with concepts and ends up in some recursive loop on both the gcc concepts library and on range-v3. So for now I am unable to make it work :-(

mpusz avatar Feb 20 '21 23:02 mpusz

Push a branch. I'll check it out.

JohelEGP avatar Feb 20 '21 23:02 JohelEGP

OK, see the https://github.com/mpusz/units/tree/clang_support branch.

mpusz avatar Feb 20 '21 23:02 mpusz

It's currently even with master.

JohelEGP avatar Feb 20 '21 23:02 JohelEGP

Sorry, try now.

mpusz avatar Feb 20 '21 23:02 mpusz

I'll need to compile Clang 13 first.

JohelEGP avatar Feb 21 '21 00:02 JohelEGP

I was able to compile quantity_test.cpp with https://github.com/johelegp/units-1/commit/0dcd2940b77fcfcf67e2783b395b34fb5c6a14f6 (-DUNITS_DOWNCAST_MODE=0, libstdc++10). Otherwise, I get error: redefinition of 'downcast_guide'. Everything's too buggy.

JohelEGP avatar Feb 21 '21 06:02 JohelEGP

So do we target clang 12 or 13?

mpusz avatar Feb 21 '21 09:02 mpusz

Little time has passed since Clang 12 froze and development Clang 13 started, so there should be little to no difference right now. I'd say the major blockers to adoption are #211 or -DUNITS_DOWNCAST_MODE=1 (due to the error: redefinition of 'downcast_guide' mentioned above).

JohelEGP avatar Feb 21 '21 17:02 JohelEGP

I was able to get past error: redefinition of 'downcast_guide' by doing this change in downcasting.h:

-  if constexpr(has_downcast_guide<T> && !has_downcast_poison_pill<T>)
+  if constexpr(has_downcast_guide<downcast_base<T>> && !has_downcast_poison_pill<T>)

which is what's actually used in the return statement. Presumably, has_downcast_poison_pill should change accordingly.

JohelEGP avatar Feb 21 '21 17:02 JohelEGP

there should be little to no difference right now.

Not really. Compare this:

  • main: https://github.com/llvm/llvm-project/blob/main/libcxx/include/concepts
  • 12: https://github.com/llvm/llvm-project/blob/release/12.x/libcxx/include/concepts

mpusz avatar Feb 21 '21 18:02 mpusz

That's the library side, though. I'll work it out on Clang trunk, and then you and maybe I could check how Clang 12 fares.

JohelEGP avatar Feb 21 '21 18:02 JohelEGP

OK, I use https://apt.llvm.org/ so it is easy to have both clang-12 and clang-13-dev (both with their libc++ versions) at the same time being up-to-date all the time.

mpusz avatar Feb 21 '21 18:02 mpusz

I think Clang 13 is ready. All tests compile and pass, as do the examples. glide_computer.cpp has some warnings and I have yet to test linear_algebra.cpp, though.

JohelEGP avatar Feb 21 '21 21:02 JohelEGP

https://en.cppreference.com/w/cpp/compiler_support lists Clang 13 and 14 as partially supporting lambdas in unevaluated contexts. I personally haven't had issues using them since Clang 14.

JohelEGP avatar Nov 10 '21 14:11 JohelEGP