Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invariant not called on extern(C++) classes #20924

Open
dkorpel opened this issue Feb 27, 2025 · 0 comments
Open

invariant not called on extern(C++) classes #20924

dkorpel opened this issue Feb 27, 2025 · 0 comments
Labels
Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code

Comments

@dkorpel
Copy link
Contributor

dkorpel commented Feb 27, 2025

Found while working on DMD itself, which uses extern(C++) classes for its AST.

extern(C++) class C
{
    invariant { assert(0); }
    void f() {}
}

void main()
{
    auto c = new C();
    c.f();
}

Expected behavior: the same as you get when you change it to extern(D) class C: Assertion failure
Actual behavior: the program runs, exits with status 0

If this is intentional, it should be documented somewhere. Either in https://dlang.org/spec/class.html#invariants or https://dlang.org/dmd-linux.html#switch-check if it's considered an implementation detail.

@thewilsonator thewilsonator added the Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code label Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code
Projects
None yet
Development

No branches or pull requests

2 participants