Page MenuHomePhabricator

Implement modernize-use-constraints
Needs ReviewPublic

Authored by ccotter on Jan 16 2023, 10:06 PM.

Details

Reviewers
njames93
Summary

Add new check to replace enable_if with C++20 constraints

Diff Detail

Event Timeline

ccotter created this revision.Jan 16 2023, 10:06 PM
Herald added a project: Restricted Project. · View Herald Transcript
ccotter requested review of this revision.Jan 16 2023, 10:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2023, 10:06 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

For the sake of demonstration, https://github.com/llvm/llvm-project/commit/9c556ce59edf5a4293d4497d5815544afc0eb878 is the result of running this tool on all headers under clang/include/clang and llvm/include/llvm.

Overall, we could eventually upgrade code in three stages, each a separate reusable check.

  1. enable_if -> requires clauses
  2. replace the non _v templates to the _v variants is_same -> is_same_v or the equivalent concept same_as
  3. replace requires clause on declarations to be template type constraint (replace template <typename T> void foo() requires std::same_as<T, int> void foo() {} to template <std::same_as<int> T> void foo() {}
  1. replace the non _v templates to the _v variants is_same -> is_same_v or the equivalent concept same_as

See D137302

  1. replace the non _v templates to the _v variants is_same -> is_same_v or the equivalent concept same_as

See D137302

Awesome!

ccotter updated this revision to Diff 491127.Jan 21 2023, 9:53 PM
  • Add fno-delayed-template-parsing
ccotter updated this revision to Diff 491201.Jan 22 2023, 12:51 PM
  • Use nested namespaces
ccotter updated this revision to Diff 493050.Jan 28 2023, 6:35 PM

Rebase + Simplify match logic

This is more or less ready for review (not planning on making any further changes; there are more features to be added, but I was thinking of handling those in follow up changesets). I know it's a relatively large review, but let me know if anyone can take a first pass. Thanks!