Skip to content

Bug with pointer and non-trivial class layout #535

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.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions