tidy: add modernize-use-using #25695

pull fanquake wants to merge 2 commits into bitcoin:master from fanquake:tidy_modernize_use_using changing 60 files +148 −144
  1. fanquake commented at 10:19 AM on July 25, 2022: member

    Refactor and introduce modernize-use-using into our clang-tidy job. Given we already use both, consolidate to the later.

    See: https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/modernize-use-using.html.

  2. aureleoules commented at 10:53 AM on July 25, 2022: contributor

    Concept ACK

    I see you refactored typedefs in *.cpp files, can it be done in header files as well?

  3. DrahtBot commented at 6:27 PM on July 25, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26177 (refactor / kernel: Move non-gArgs chainparams functionality to kernel by TheCharlatan)
    • #26158 (bench: add "priority level" to the benchmark framework by furszy)
    • #25620 (wallet: Introduce AddressBookManager by furszy)
    • #25572 (refactor: Introduce EvictionManager and use it for the inbound eviction logic by dergoegge)
    • #21590 (Safegcd-based modular inverses in MuHash3072 by sipa)
    • #17786 (refactor: Nuke policy/fees->mempool circular dependencies by hebasto)
    • #16195 (util: Use void* throughout support/lockedpool.h by jkczyz)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. fanquake force-pushed on Jul 29, 2022
  5. fanquake force-pushed on Aug 1, 2022
  6. fanquake commented at 9:24 AM on August 1, 2022: member

    I see you refactored typedefs in *.cpp files, can it be done in header files as well?

    Added some changes to header files.

  7. DrahtBot added the label Needs rebase on Aug 5, 2022
  8. fanquake force-pushed on Aug 15, 2022
  9. DrahtBot removed the label Needs rebase on Aug 15, 2022
  10. in src/test/fuzz/crypto_diff_fuzz_chacha20.cpp:46 in f5284d39a2 outdated
      42 | @@ -43,10 +43,10 @@ typedef unsigned char u8;
      43 |  /* ------------------------------------------------------------------------- */
      44 |  /* Data structures */
      45 |  
      46 | -typedef struct
      47 | +using ECRYPT_ctx = struct
    


    ryanofsky commented at 6:53 PM on August 18, 2022:

    In commit "refactor: use "using" over "typedef"" (f5284d39a2b78bb07655c397386b9741495b6d41)

    This one is a little weird because it was a C-style struct typedef. Should probably just be updated struct ECRYPT_ctx {


    fanquake commented at 7:54 AM on August 19, 2022:

    Applied this suggestion.

  11. ryanofsky commented at 6:54 PM on August 18, 2022: contributor

    Code review ACK d1885b434f3612ac1efe926e230a440bd7eed366

  12. ryanofsky approved
  13. fanquake force-pushed on Aug 19, 2022
  14. fanquake force-pushed on Aug 19, 2022
  15. fanquake commented at 3:33 PM on August 19, 2022: member

    Rebased for #25707.

  16. fanquake requested review from aureleoules on Aug 19, 2022
  17. aureleoules commented at 10:31 PM on August 19, 2022: contributor

    I believe you can change these as well.

    <details> <summary>Git diff</summary>

    diff --git a/src/blockencodings.h b/src/blockencodings.h
    index 67c4e5715..700ebb252 100644
    --- a/src/blockencodings.h
    +++ b/src/blockencodings.h
    @@ -74,14 +74,13 @@ struct PrefilledTransaction {
         SERIALIZE_METHODS(PrefilledTransaction, obj) { READWRITE(COMPACTSIZE(obj.index), Using<TransactionCompression>(obj.tx)); }
     };
     
    -typedef enum ReadStatus_t
    -{
    +using ReadStatus = enum ReadStatus_t {
         READ_STATUS_OK,
         READ_STATUS_INVALID, // Invalid object, peer is sending bogus crap
         READ_STATUS_FAILED, // Failed to process object
         READ_STATUS_CHECKBLOCK_FAILED, // Used only by FillBlock to indicate a
                                        // failure in CheckBlock.
    -} ReadStatus;
    +};
     
     class CBlockHeaderAndShortTxIDs {
     private:
    diff --git a/src/protocol.h b/src/protocol.h
    index b85dc0d82..af105f90a 100644
    --- a/src/protocol.h
    +++ b/src/protocol.h
    @@ -33,7 +33,7 @@ public:
         static constexpr size_t MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE;
         static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
         static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
    -    typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
    +    using MessageStartChars = unsigned char[MESSAGE_START_SIZE];
     
         explicit CMessageHeader() = default;
     
    diff --git a/src/rpc/server.h b/src/rpc/server.h
    index 01e855605..31fd72ce3 100644
    --- a/src/rpc/server.h
    +++ b/src/rpc/server.h
    @@ -84,7 +84,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface);
      */
     void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);
     
    -typedef RPCHelpMan (*RpcMethodFnType)();
    +using RpcMethodFnType = RPCHelpMan (*)();
     
     class CRPCCommand
     {
    diff --git a/src/script/bitcoinconsensus.h b/src/script/bitcoinconsensus.h
    index 8fea42e4b..fda5e3c5e 100644
    --- a/src/script/bitcoinconsensus.h
    +++ b/src/script/bitcoinconsensus.h
    @@ -33,7 +33,7 @@ extern "C" {
     
     #define BITCOINCONSENSUS_API_VER 1
     
    -typedef enum bitcoinconsensus_error_t
    +using bitcoinconsensus_error = enum bitcoinconsensus_error_t
     {
         bitcoinconsensus_ERR_OK = 0,
         bitcoinconsensus_ERR_TX_INDEX,
    @@ -41,7 +41,8 @@ typedef enum bitcoinconsensus_error_t
         bitcoinconsensus_ERR_TX_DESERIALIZE,
         bitcoinconsensus_ERR_AMOUNT_REQUIRED,
         bitcoinconsensus_ERR_INVALID_FLAGS,
    -} bitcoinconsensus_error;
    +};
     
     /** Script verification flags */
     enum
    diff --git a/src/script/script_error.h b/src/script/script_error.h
    index 44e68fe0f..2674ca8dd 100644
    --- a/src/script/script_error.h
    +++ b/src/script/script_error.h
    @@ -8,7 +8,7 @@
     
     #include <string>
     
    -typedef enum ScriptError_t
    +using ScriptError = enum ScriptError_t
     {
         SCRIPT_ERR_OK = 0,
         SCRIPT_ERR_UNKNOWN_ERROR,
    @@ -83,7 +83,7 @@ typedef enum ScriptError_t
         SCRIPT_ERR_SIG_FINDANDDELETE,
     
         SCRIPT_ERR_ERROR_COUNT
    -} ScriptError;
    +};
     
     #define SCRIPT_ERR_LAST SCRIPT_ERR_ERROR_COUNT
     
    diff --git a/src/support/events.h b/src/support/events.h
    index 0a74d0236..24f807ae3 100644
    --- a/src/support/events.h
    +++ b/src/support/events.h
    @@ -19,7 +19,7 @@ struct type##_deleter {\
         }\
     };\
     /* unique ptr typedef */\
    -typedef std::unique_ptr<struct type, type##_deleter> raii_##type
    +using raii_##type = std::unique_ptr<struct type, type##_deleter>;
     
     MAKE_RAII(event_base);
     MAKE_RAII(event);
    diff --git a/src/support/lockedpool.h b/src/support/lockedpool.h
    index 1c0d0669b..bbbb5d374 100644
    --- a/src/support/lockedpool.h
    +++ b/src/support/lockedpool.h
    @@ -139,7 +139,8 @@ public:
     
         /** Callback when allocation succeeds but locking fails.
          */
    -    typedef bool (*LockingFailed_Callback)();
    +    using LockingFailed_Callback = bool (*)();
     
         /** Memory statistics. */
         struct Stats
    diff --git a/src/tinyformat.h b/src/tinyformat.h
    index bedaa1400..e938ea046 100644
    --- a/src/tinyformat.h
    +++ b/src/tinyformat.h
    @@ -221,7 +221,9 @@ struct is_convertible
     
     
     // Detect when a type is not a wchar_t string
    -template<typename T> struct is_wchar { typedef int tinyformat_wchar_is_not_supported; };
    +template<typename T> struct is_wchar { 
    +    using tinyformat_wchar_is_not_supported = int;
    +};
     template<> struct is_wchar<wchar_t*> {};
     template<> struct is_wchar<const wchar_t*> {};
     template<int n> struct is_wchar<const wchar_t[n]> {};
    @@ -332,7 +334,7 @@ inline void formatValue(std::ostream& out, const char* /*fmtBegin*/,
     #ifndef TINYFORMAT_ALLOW_WCHAR_STRINGS
         // Since we don't support printing of wchar_t using "%ls", make it fail at
         // compile time in preference to printing as a void* at runtime.
    -    typedef typename detail::is_wchar<T>::tinyformat_wchar_is_not_supported DummyType;
    +    using DummyType = typename detail::is_wchar<T>::tinyformat_wchar_is_not_supported;
         (void) DummyType(); // avoid unused type warning with gcc-4.8
     #endif
         // The mess here is to support the %c and %p conversions: if these
    @@ -958,7 +960,7 @@ class FormatList
     };
     
     /// Reference to type-opaque format list for passing to vformat()
    -typedef const FormatList& FormatListRef;
    +using FormatListRef = const FormatList&;
     
     
     namespace detail {
    

    </details>

  18. fanquake commented at 3:03 PM on August 20, 2022: member

    I believe you can change these as well.

    Thanks. Incorporated those are that aren't upstream code, i.e tinyformat.

  19. fanquake force-pushed on Aug 20, 2022
  20. aureleoules commented at 7:51 AM on August 22, 2022: contributor

    ACK 313241d757c022d978d87e1abd9ab4bb68d45986

  21. maflcko commented at 4:41 PM on August 24, 2022: member

    What is the point of this other than causing merge conflicts, given that the linter doesn't even enforce any of this in header files?

    I mean it is great that we have clang-tidy but we should use it for transformations/checks that prevent bugs, not as an excuse for one-off (+ endless follow-up) style cleanups. Especially if the new rule doesn't even enforce the new style.

  22. ryanofsky commented at 5:23 PM on August 24, 2022: contributor

    Makes sense that if you're going to to use clang-tidy for a cleanup, you should probably look into it enabling it as a lint-check too so the cleanup does not need to be repeated. I don't have so much of a problem with one-off cleanups or repeated cleanups, though.

  23. in src/blockencodings.h:77 in 4f510b0612 outdated
      73 | @@ -74,14 +74,14 @@ struct PrefilledTransaction {
      74 |      SERIALIZE_METHODS(PrefilledTransaction, obj) { READWRITE(COMPACTSIZE(obj.index), Using<TransactionCompression>(obj.tx)); }
      75 |  };
      76 |  
      77 | -typedef enum ReadStatus_t
      78 | +using ReadStatus = enum ReadStatus_t
    


    ryanofsky commented at 5:26 PM on August 24, 2022:

    In commit "refactor: use "using" over "typedef"" (4f510b061229f54b5c0d5dcbd91ea28cfca63dae)

    Can just say enum ReadStatus { here. ReadStatus_t is never referenced.

  24. in src/script/bitcoinconsensus.h:36 in 313241d757 outdated
      32 | @@ -33,15 +33,15 @@ extern "C" {
      33 |  
      34 |  #define BITCOINCONSENSUS_API_VER 1
      35 |  
      36 | -typedef enum bitcoinconsensus_error_t
      37 | +using bitcoinconsensus_error = enum bitcoinconsensus_error_t
    


    ryanofsky commented at 5:30 PM on August 24, 2022:

    In commit "tidy: enable modernize-use-using" (313241d757c022d978d87e1abd9ab4bb68d45986)

    Probably should revert this change if this header is supposed to be usable from C code. I assume extern "C" { above means it should be.

  25. ryanofsky approved
  26. ryanofsky commented at 5:35 PM on August 24, 2022: contributor

    Conditional code review ACK 313241d757c022d978d87e1abd9ab4bb68d45986 if it is ok to use c++ syntax in the bitcoinconsensus.h file

  27. refactor: use "using" over "typedef" dfd911500b
  28. tidy: enable modernize-use-using
    https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/modernize-use-using.html
    6edd9716e3
  29. fanquake force-pushed on Aug 31, 2022
  30. in src/script/script_error.h:11 in dfd911500b outdated
       7 | @@ -8,7 +8,7 @@
       8 |  
       9 |  #include <string>
      10 |  
      11 | -typedef enum ScriptError_t
      12 | +using ScriptError = enum ScriptError_t
    


    ryanofsky commented at 5:42 PM on September 1, 2022:

    In commit "refactor: use "using" over "typedef"" (dfd911500bdd1a9542f79d1a823b1b66245ad76c)

    Would be good for a followup (possible future PR) to drop ScriptError_t in tests and just change this to enum ScriptError

  31. ryanofsky approved
  32. ryanofsky commented at 5:45 PM on September 1, 2022: contributor

    Code review ACK 6edd9716e3980b2e0c3894fc48672c7ae15dd4f2. Only changes since last review were suggested cleanups

  33. DrahtBot commented at 5:09 PM on October 20, 2022: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  34. DrahtBot added the label Needs rebase on Oct 20, 2022
  35. fanquake closed this on Dec 5, 2022

  36. fanquake deleted the branch on Nov 6, 2023
  37. bitcoin locked this on Nov 5, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 09:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me