Skip to content

Bug with pointer and non-trivial class layout #535

Closed
@lookfwd

Description

@lookfwd

On the following code:

#include <assert.h>

unsigned cnt = 0;

struct Foo {
    //int i;
};

class Box
{
    unsigned * monitor;
    Foo f;

    void op()
    {
        assert(monitor == &cnt);

        *monitor = 1;
    }
};

class Container
{
    Box boxes[1];
};

int main()
{
    Container c;

    c.boxes[0].monitor = &cnt;
    c.boxes[0].op();

    assert(cnt == 0u);

    return 0;
}

depending on if Foo f; exists (try commenting it out), the checker does or doesn't work (despite the fact that Foo is empty.

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