Naios / function2

Improved and configurable drop-in replacement to std::function that supports move only types, multiple overloads and more
http://naios.github.io/function2
Boost Software License 1.0
545 stars 46 forks source link

Some compiler warnings are generated #30

Open hadrielk opened 5 years ago

hadrielk commented 5 years ago

@Naios

This is relatively minor, but I thought I'd mention it before I forget about them: building function2 strictly as a copied header with clang can trigger a few warnings, if you enable them.


Commit Hash

5b8e6de

Expected Behavior

Builds cleanly (no warnings).

Actual Behavior

Building generates warnings, as follows:

  1. An uninitialized-member warning due to member variables cmd_ and vtable_ not having default initializers and not being explicitly initialized in the default constructor for class type_erasure::tables::vtable.
member 'cmd_' is missing from constructor initializer list [-Werror,-Wuninitialized-member]
member 'vtable_' is missing from constructor initializer list [-Werror,-Wuninitialized-member]

Easily fixed by changing the member declarations this:

    command_function_t cmd_{nullptr};
    typename invoke_table_t::type vtable_{nullptr};
  1. The use of the variable name allocator in various places triggers a shadow warning, due to the base class in libstdc++ also using it. (note: this is a gcc warning and was built with gcc, not clang)
declaration of 'allocator' shadows a member of ... [-Werror=shadow]
include/c++/7/bits/allocator.h:109:5: note: shadowed declaration is here
  1. The enum class opcode enumerations use doxygen-like comments that don't follow doxygen correctly, triggering a documentation warning.
not a Doxygen trailing comment [-Werror,-Wdocumentation]
     op_move,         //< Move the object and set the vtable
                      ^~~
                      ///<

Changing them to this fixes it:

enum class opcode
{
    op_move,         ///< Move the object and set the vtable
    op_copy,         ///< Copy the object and set the vtable
    op_destroy,      ///< Destroy the object and reset the vtable
    op_weak_destroy, ///< Destroy the object without resetting the vtable
    op_fetch_empty,  ///< Stores true or false into the to storage
                     ///< to indicate emptiness
};

Steps to Reproduce

Build using clang with -Weverything or the specific warnings described earlier, except for (2) which was found using gcc.

This was built simply as a copied header - i.e., not using the CMake settings in this project. (built for C++17)

Your Environment

Naios commented 5 years ago

Thanks for your report. The uninitialized-member warning is triggered because some members are initialized in the content of the constructor, mayne this can be improved. The other warnings will be fixed soon.