Giter Club home page Giter Club logo

Comments (8)

lewissbaker avatar lewissbaker commented on July 17, 2024 2

Note that on modern versions of clang std::forward/move now get translated to intrinsics which shouldn’t have the same template instantiation overhead.

from libunifex.

ccotter avatar ccotter commented on July 17, 2024 1

I'd be happy to do a first pass at this and report back. One of my side hobbies it tinkering with clang-tidy and have some experience with the checks that verify correct uses of move, forward, and universal references.

from libunifex.

ccotter avatar ccotter commented on July 17, 2024 1

Ok, these two checks are of interest (both of which would appear in the next LLVM release version 17).

Both help identify all cases where functions do not use std::move(rvalue_ref_param) or static_cast<T&&>(universal_ref_param) (or std::forward<T&&>(universal_ref_param) if you end up preferring that coding style). E.g.,

/home/ccotter/git/libunifex/include/unifex/async_mutex.hpp:119:46: warning: rvalue reference parameter 's' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
  119 |     tag_invoke(tag_t<connect>, lock_sender &&s, Receiver &&r) noexcept {
      |                                              ^
/home/ccotter/git/libunifex/include/unifex/async_mutex.hpp:119:60: warning: forwarding reference parameter 'r' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward]
  119 |     tag_invoke(tag_t<connect>, lock_sender &&s, Receiver &&r) noexcept {

Both checks are expecting code to always use the "named cast" using move or forward. The checks won't emit any kind of fixits though. Below are the counts of each diagnostic for all header includes:

     36 [cppcoreguidelines-rvalue-reference-param-not-moved]
    635 [cppcoreguidelines-missing-std-forward]

If you'd like, I can do a first pass to fix the parameters that use C-cast instead of std::move().

from libunifex.

ccotter avatar ccotter commented on July 17, 2024 1

Do you know anything about running clang-tidy as a linter

Unfortunately I'm not familiar with GitHub CI specifically. Googling around shows there's https://github.com/marketplace/actions/clang-tidy-review. What's needed generally to run clang-tidy is a build capable of producing a compile_comands.json (which cmake can do at configure time), and a .clang-tidy config file listing the checks to enable (and per-check options in some cases). Let me see if I can play with this on a personal project and see if it's easy to setup.

from libunifex.

ispeters avatar ispeters commented on July 17, 2024 1

Oh, and that clang-tidy-review … thingy looks pretty useful! @janondrusek has done a lot more than I have to maintain our GitHub CI so I think you two might be best suited to discuss whether and how to add clang-tidy-review to the mix.

from libunifex.

ispeters avatar ispeters commented on July 17, 2024

Those look awesome, @ccotter. A first pass would be most welcome.

Do you know anything about running clang-tidy as a linter as part of GitHub CI because I imagine that would help us stay clean.

from libunifex.

ccotter avatar ccotter commented on July 17, 2024

Just to confirm, should I also look at migrating static_cast or C style forwarding casts to std::forward? I ended up writing a clang-tidy tool to do behavior preserving conversion (and it'll can optionally try to replace moves, although that transform is not possible to be behavior preserving in all cases). That said, we should still review all cases in case the intent of (T&&)t on a forwarding reference should not even be using a forwarding reference at all.

from libunifex.

ispeters avatar ispeters commented on July 17, 2024

should I also look at migrating static_cast or C style forwarding casts to std::forward?

Yes, please! We're having a discussion on #552 about what to do when forwarding not-really-forwarding-references, which I think makes this issue nuanced, but, for clear cases of moves and forwards, I think we should standardize on std::move and std::forward so if you're interested in doing the clean-up, I'm quite happy to review and merge.

from libunifex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.