Skip to content

Using this in constructor seems to be UB #2384

Closed
@tom-anders

Description

@tom-anders

Input C/C++ Header

class Foo {
	Foo() { printf("%d", this);} 
	void bar() const { printf("%d", this);} 
}

When using this from Rust like this

let foo = Foo::new();
foo.bar();

Then the printf calls will print different numbers. This is probably expected behavior, but it doesn't seem to be documented (would've saved me 1 hour of debugging). For example, people may use the this pointer to pass the class as some listener interface to one of its fields.

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