Skip to content

vir::struct_size_v returns zero for structs that contain types with certain constructors #48

Description

@the-argus

The following does not compile due to the static assert failing:

class Ambiguous
{
    private:
        int i;
    public:
        constexpr Ambiguous(int _i) : i(_i) {}
};

struct ContainsAmbiguous
{
    float a;
    float b;
    Ambiguous ambiguous;
};

static_assert(vir::struct_size_v<ContainsAmbiguous> != 0);

To see what's wrong I tried reproducing the contents of requires clauses in vir::detail::brace_constructible_impl:

inline auto testinstance = ContainsAmbiguous{
    {vir::detail::anything_but_base_of<ContainsAmbiguous>{}},
    {vir::detail::anything_but_base_of<ContainsAmbiguous>{}},
    {vir::detail::anything_but_base_of<ContainsAmbiguous>{}}, // call to constructor of "Ambiguous" is ambiguous
};

Whereas this compiles:

inline auto testinstance = ContainsAmbiguous{
    vir::detail::anything_but_base_of<ContainsAmbiguous>{},
    vir::detail::anything_but_base_of<ContainsAmbiguous>{},
    vir::detail::anything_but_base_of<ContainsAmbiguous>{},
};

That's a recreation of this clause from brace_constructible_impl:

requires { T{{((void)Indexes, anything_but_base_of<T>())}...}; }

The additional curly braces being added in c1e9325ca880b908746f0c17c02df379889faa6d.

So it seems like although the additional braces prevent confusion due to brace elision they also opt into explicit constructors of the member variables which introduces ambiguity. Not sure what the correct approach here is, if there's a way to make both work at once.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions