[Solved] C++ mysterious code. any security issue? [closed]


This with g++ compiles, and I don’t think there’s any UB

struct Va
{
    Va(struct Foo&, int) {}
};

int operator++(const Va&, int) { return 42; }

struct Foo
{
    Va va;
    Foo(Foo &afoo) : va(afoo,va++) {}
};

to be specific operator++ is not doing anything with the not-yet-initialized va data member. It’s more or less like passing *this (as reference) or this (as pointer) to a base class or a function in the initialization list… it’s correctly reported by some compilers as a dangerous operation but it’s legal if the referenced object is not accessed (and it’s actually sometimes useful if you only need the address).

3

solved C++ mysterious code. any security issue? [closed]