Skip to content

get_or fails for temporaries #1752

Description

@TerensTare

Hi, I want to use get_or to get a value out of a table or if missing use a default, but I'm having some trouble making it work for a specific use case. To my understanding, the following should work just fine:

struct pos { int x, y; };

auto p = lua_table.get_or("myPos", pos{0, 0});

However, it fails to compile in MSVC, GCC and Clang, whereas the following works just fine:

struct pos { int x, y; };

pos alt{0, 0};
auto p = lua_table.get_or("myPos", alt);

Is this the intended behavior or is it a bug? If this is intended, I think it's best if we get a static_assert saying that our "alternative" should be a lvalue (I guess?), it should be more helpful than the current state of things.

Here's a godbolt link with a complete example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions