[Issue 23357] New: ImportC: compatible types with definitions leads to redeclaration error when used from D.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 22 07:00:02 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23357

          Issue ID: 23357
           Summary: ImportC: compatible types with definitions leads to
                    redeclaration error when used from D.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dave287091 at gmail.com

Follow up to 22674, which seems to only be fixed for for opaque types.

Repeating the example, but with the struct having a definition:
Consider the following files:

// foo_def.h
typedef struct Foo *FooRef;
struct Foo {
    int x;
};

// maker.h
#include "foo_def.h"
FooRef make_foo(void);

// freer.h
#include "foo_def.h"
void free_foo(FooRef foo);

Which then preprocesses to:

// maker.i
typedef struct Foo *FooRef;
struct Foo {
    int x;
};
FooRef make_foo(void);

// freer.i
typedef struct Foo *FooRef;
struct Foo { // freer.i(2): Error: struct `freer.Foo` already exists at
maker.i(2). Perhaps in another function with the same name?
    int x;
};
void free_foo(FooRef foo);

You then try to use it in your D program:

// use_foo.d
import maker;
import freer;

void do_foo(){
    FooRef f = make_foo();
    free_foo(f);
}

--


More information about the Digitalmars-d-bugs mailing list