[Issue 24022] New: ImportC: Error: attribute `__anonymous` is used as a type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 28 14:07:21 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24022
Issue ID: 24022
Summary: ImportC: Error: attribute `__anonymous` is used as a
type
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: firemage.dima at gmail.com
Hi,
This issue is related to Issue 23662.
Minimal example
===============
```c
// testlib.c
typedef enum {
A = 1,
} E;
```
```d
// test.d
import testlib;
auto some_d_func(E v) {
return v;
}
void main(string[] args) {
E expected = A;
auto res = some_d_func(A);
assert (res == A);
assert (res == expected);
}
```
This example produces following error:
```
dmd test.d testlib.c
test.d(3): Error: attribute `__anonymous` is used as a type
```
Other example
=============
```c
// testlib.c
typedef enum {
A = 1,
} E;
```
```d
// test2.d
import testlib;
auto some_d_other_func() {
const struct R {
E r;
this(in E vparam) {
r = vparam;
}
}
return R(A);
}
void main(string[] args) {
E expected = A;
auto res = some_d_other_func(A);
assert (res.r == A);
assert (res.r == expected);
}
```
This example produces following error:
```
dmd test2.d testlib.c
test2.d(5): Error: attribute `__anonymous` is used as a type
test2.d(7): Error: attribute `__anonymous` is used as a type
test2.d(16): Error: attribute `__anonymous` is used as a type
```
Real example with libpq
=======================
```c
//libpq.c
#include <postgresql/libpq-fe.h>
#include <postgresql/postgres_ext.h>
```
```d
// sample code from some d file.
@safe struct Result {
// ...
auto status() {
const struct ResultStatus {
ExecStatusType statusType;
this(in ExecStatusType statusType) {
this.statusType = statusType;
}
/// Return string representation of result status
string toString() const {
return PQresStatus(statusType).fromStringz.idup;
}
}
return ResultStatus(PQresultStatus(_result._pg_result));
}
}
// ....
```
--
More information about the Digitalmars-d-bugs
mailing list