Skip to content

Compiler warning when using "std::optional" as field #45

@omarmed

Description

@omarmed

Using "std::optional" within an aggregate causes a warning.

Example: [(https://godbolt.org/z/5W19cYG6d)]

#include <iostream>
#include <optional>
#include <https://raw.githubusercontent.com/boost-ext/reflect/main/reflect>

struct Prueba {
    std::optional<int> v;
};

int main() {
    auto p = Prueba{};
    reflect::for_each([&](auto I) {
        std::cout << reflect::member_name<I>(p) << " = " << typeid(reflect::get<I>(p)).name() << std::endl;
    }, p);

    return 0;
}

Compiler output:

/app/raw.githubusercontent.com/boost-ext/reflect/main/reflect:88:42: warning: inline function 'reflect::detail::any::operator int<int>' is not defined [-Wundefined-inline]
   88 | struct any { template<class T> constexpr operator T() const noexcept; };
      |                                          ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../include/c++/14.0.1/optional:210:17: note: used here
  210 |             : _M_value(std::forward<_Args>(__args)...)
      |                        ^
1 warning generated.

It's just a warning, and the program works correctly, but it gives problems when using "-Werror"

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