SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.
Other
662 stars 101 forks source link

Warning C4834 in Log.cpp #179

Closed syby119 closed 2 months ago

syby119 commented 3 months ago

In efsw/src/efsw/Log.cpp line 45

    efDEBUG( "%s\n", LastError.c_str() );

Compiler MSVC complains that warning C4834: discarding return value of function with [[nodiscard]] attribute.

This is because when the compiler is MSVC, the macro efDEBUG is empty. This leads to the macro expansion to

    ("%s\n", LastError.c_str());

And the declaration of std::string::c_str() is marked as [[no discard]] in MSVC

    _NODISCARD _CONSTEXPR20 _Ret_z_ const _Elem* c_str() const noexcept {
        return _Mypair._Myval2._Myptr();
    }

There are multiple solutions to fix this warning, one choice is change the macro efDEBUG to

#define efDEBUG(...) {}