fs: work around u8path deprecated-declaration warnings with libc++ #25808

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:fix_24682 changing 2 files +5 −1
  1. fanquake commented at 8:07 AM on August 9, 2022: member

    When building in c++20 mode using libc++, the following warning is emitted:

    ./fs.h:72:29: warning: 'u8path<std::string>' is deprecated [-Wdeprecated-declarations]
        return std::filesystem::u8path(utf8_str);
                                ^
    /usr/lib/llvm-14/bin/../include/c++/v1/__filesystem/u8path.h:72:27: note: 'u8path<std::string>' has been explicitly marked deprecated here
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
                              ^
    /usr/lib/llvm-14/bin/../include/c++/v1/__config:1042:43: note: expanded from macro '_LIBCPP_DEPRECATED_WITH_CHAR8_T'
                                              ^
    /usr/lib/llvm-14/bin/../include/c++/v1/__config:1007:48: note: expanded from macro '_LIBCPP_DEPRECATED'
                                                   ^
    1 warning generated.
    

    as u8path<std::string> is deprecated starting with C++20.

    Fixes: #24682.

  2. fanquake force-pushed on Aug 9, 2022
  3. Sjors commented at 9:45 AM on August 10, 2022: member

    tACK 6bf6234790099cce5585b62742ffb572054973e1

    Although I don't see any other deprecation warnings, I like that we only suppress this specific one.

  4. hebasto commented at 10:37 AM on August 10, 2022: member

    I do prefer @MarcoFalke's alternative which also allows to drop the global _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING:

    diff --git a/build_msvc/common.init.vcxproj.in b/build_msvc/common.init.vcxproj.in
    index f7169a346d..e84ac03623 100644
    --- a/build_msvc/common.init.vcxproj.in
    +++ b/build_msvc/common.init.vcxproj.in
    @@ -90,7 +90,7 @@
           <AdditionalOptions>/utf-8 /Zc:__cplusplus /std:c++20 %(AdditionalOptions)</AdditionalOptions>
           <DisableSpecificWarnings>4018;4244;4267;4334;4715;4805;4834</DisableSpecificWarnings>
           <TreatWarningAsError>true</TreatWarningAsError>
    -      <PreprocessorDefinitions>_SILENCE_CXX20_U8PATH_DEPRECATION_WARNING;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING;ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;_WIN32_IE=0x0501;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    +      <PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING;ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;_WIN32_IE=0x0501;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
           <AdditionalIncludeDirectories>..\..\src;..\..\src\minisketch\include;..\..\src\univalue\include;..\..\src\secp256k1\include;..\..\src\leveldb\include;..\..\src\leveldb\helpers\memenv;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
         </ClCompile>
         <Link>
    diff --git a/src/fs.h b/src/fs.h
    index e8b34319bb..ac58c4a2ba 100644
    --- a/src/fs.h
    +++ b/src/fs.h
    @@ -69,7 +69,11 @@ public:
     
     static inline path u8path(const std::string& utf8_str)
     {
    +#if __cplusplus < 202002L
         return std::filesystem::u8path(utf8_str);
    +#else
    +    return std::filesystem::path(std::u8string{utf8_str.begin(), utf8_str.end()});
    +#endif
     }
     
     // Disallow implicit std::string conversion for absolute to avoid
    
  5. fanquake commented at 11:01 AM on August 10, 2022: member

    I do prefer @MarcoFalke's #24682 (comment)

    I don't really want to start introducing __cplusplus version checks into our code.

    which also allows to drop the global _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING:

    Why does dropping that matter? It's being used as intended.

  6. MarcoFalke commented at 11:20 AM on August 10, 2022: member

    No opinion on what to do, but the new code should ideally be the version we'll adopt once (and if) we bump to C++20

  7. ryanofsky approved
  8. ryanofsky commented at 7:05 PM on August 15, 2022: contributor

    Code review ACK 6bf6234790099cce5585b62742ffb572054973e1. I do think hebasto/marco's solution #25808 (comment) is cleaner, more standard, and more future proof but both solutions are good.

  9. fs: work around u8path deprecated-declaration warnings with libc++
    When building in c++20 mode using libc++, the following warning is
    emitted:
    ```bash
    ./fs.h:72:29: warning: 'u8path<std::string>' is deprecated [-Wdeprecated-declarations]
        return std::filesystem::u8path(utf8_str);
                                ^
    /usr/lib/llvm-14/bin/../include/c++/v1/__filesystem/u8path.h:72:27: note: 'u8path<std::string>' has been explicitly marked deprecated here
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
                              ^
    /usr/lib/llvm-14/bin/../include/c++/v1/__config:1042:43: note: expanded from macro '_LIBCPP_DEPRECATED_WITH_CHAR8_T'
                                              ^
    /usr/lib/llvm-14/bin/../include/c++/v1/__config:1007:48: note: expanded from macro '_LIBCPP_DEPRECATED'
                                                   ^
    1 warning generated.
    ```
    
    as u8path<std::string> is deprecated starting with c++20.
    
    Fixes: #24682.
    
    Co-authored-by: MacroFake <falke.marco@gmail.com>
    Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    ced00f5a2e
  10. fanquake force-pushed on Aug 19, 2022
  11. fanquake commented at 8:11 AM on August 19, 2022: member

    I'm still not a fan of the version checking, but I've pushed up the alternative solution.

  12. fanquake renamed this:
    fs: suppress u8path deprecated-declaration warnings with libc++
    fs: work around u8path deprecated-declaration warnings with libc++
    on Aug 19, 2022
  13. MarcoFalke commented at 8:16 AM on August 19, 2022: member

    review ACK ced00f5a2e2b8623d1ee6a9afef80fc5df08d509

    Looks like this creates 3 copies of the string, but they should all be moved so it has probably no performance impact. Regardless, the helper shouldn't be used in hot loops anyway.

  14. hebasto approved
  15. hebasto commented at 8:43 AM on August 19, 2022: member

    ACK ced00f5a2e2b8623d1ee6a9afef80fc5df08d509

  16. MarcoFalke merged this on Aug 19, 2022
  17. MarcoFalke closed this on Aug 19, 2022

  18. fanquake deleted the branch on Aug 19, 2022
  19. sidhujag referenced this in commit 241e31f319 on Aug 19, 2022
  20. bitcoin locked this on Aug 19, 2023

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-22 12:13 UTC

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