Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in emplace method #1605

Open
paulocoutinhox opened this issue May 25, 2024 · 2 comments
Open

Error in emplace method #1605

paulocoutinhox opened this issue May 25, 2024 · 2 comments

Comments

@paulocoutinhox
Copy link
Contributor

Hi,

Im getting this error when build:

[100%] Building CXX object engine/extensions/scripting/lua-bindings/CMakeFiles/axlua.dir/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/yasio/yasio/bindings/lyasio.cpp.o
In file included from /Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/yasio/yasio/bindings/lyasio.cpp:83:
In file included from /Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/yasio/yasio/bindings/yasio_sol.hpp:29:
/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/lua/sol/sol.hpp:6755:10: error: no member named 'construct' in 'optional<type-parameter-0-0 &>'
 6755 |                         this->construct(std::forward<Args>(args)...);
      |                         ~~~~  ^
/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/lua/sol/sol.hpp:14541:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
 14541 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
       |                                ^
/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/lua/sol/sol.hpp:17294:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
 17294 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
       |                                ^
2 warnings and 1 error generated.

My solution:

/// Constructs the value in-place, destroying the current one if there is
/// one.
///
/// \group emplace
template <class... Args>
T& emplace(Args&&... args) noexcept {
    static_assert(std::is_constructible<T, Args&&...>::value, "T must be constructible with Args");

    *this = nullopt;
    new (static_cast<void*>(this)) optional(std::in_place, std::forward<Args>(args)...);
    return **this;
}
@Maddimax
Copy link
Contributor

Maddimax commented Sep 2, 2024

I'm running into the same issue with GCC 15. Since there already is a fix ( d805d02 ), can a new release be created?

@deadlocklogic
Copy link
Contributor

Can you please create a minimal repro?
While your fix is simple, it is however semantically different from the one in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants