Skip to content

rfl::to_generic() generates MSVC warning C4702 (unreachable code) #665

@axel-dewalt

Description

@axel-dewalt

I refer you to this fragment from include/rfl/generic/Writer.hpp:

 private:
  template <class T>
  OutputVarType to_generic(const T& _var) const noexcept {
    if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
      return OutputVarType(_var);
    } else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
      return OutputVarType(_var);
    } else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
      return OutputVarType(static_cast<double>(_var));
    } else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
      return OutputVarType(static_cast<int64_t>(_var));
    } else {
      static_assert(always_false_v<T>, "Unsupported type");
    }
    return OutputVarType{};
  }

The final return generates this error message (note the line numbers in the console output are different as I'm behind dev, but the code seems to be unchanged in the latest version):

C:\reflect-cpp\include\rfl\generic\Writer.hpp(101): error C2220: the following warning is treated as an error
C:\reflect-cpp\include\rfl\generic\Writer.hpp(101): warning C4702: unreachable code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions