Comment #0 by firemage.dima — 2023-06-28T14:07:21Z
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));
}
}
// ....
```
Comment #1 by dlang-bot — 2023-06-28T16:39:18Z
@katyukha created dlang/dmd pull request #15365 "Implement test case for Issue 24022" mentioning this issue:
- Implement test case for Issue 24022
https://github.com/dlang/dmd/pull/15365
Comment #2 by carsten.schlote — 2023-06-30T08:05:25Z
Hi,
i stumbled over this regession bug, too. Simplyfied example to reproduce:
enum_decl.c:
---------------
/// @brief Type ID for signature block
typedef enum FWSIG_TYPE {
E_FWSIG_TYPE_RSA2048 = 0,
E_FWSIG_TYPE_RSA3072,
E_FWSIG_TYPE_RSA4096,
E_FWSIG_TYPE_EC256 = 16,
E_FWSIG_TYPE_ECP384,
E_FWSIG_TYPE_ECP521,
E_FWSIG_TYPE_ED25519 = 32,
E_FWSIG_TYPE_UNKNOWN = -1
}
E_FWSIG_TYPE;
---------------
use_enum_decl.d:
---------------
import enum_decl;
E_FWSIG_TYPE getEnumType(string blah)
{
E_FWSIG_TYPE type = E_FWSIG_TYPE_UNKNOWN;
return type;
}
---------------
$ dmd --version
DMD64 D Compiler v2.103.1
$ dmd -c use_enum_decl.d
use_enum_decl.d(3): Error: attribute `__anonymous` is used as a type
$ dmd-beta --version
DMD64 D Compiler v2.104.1-beta.1-163-gb549aba8d6
$ dmd-beta -c use_enum_decl.d
use_enum_decl.d(3): Error: attribute `__anonymous` is used as a type
$ ldc2 --version
LDC - the LLVM D compiler (1.32.1):
based on DMD v2.102.2 and LLVM 15.0.7
$ ldc2 -c use_enum_decl.d
# Compiles fine as previous versions of DMD did.
Comment #3 by firemage.dima — 2023-06-30T18:06:43Z
The fix seems to be ready: https://github.com/dlang/dmd/pull/15365
Waiting for review.
@Carsten Schlote, Please, test the fix on your example (if you have time).
Comment #4 by schlote — 2023-07-03T08:00:14Z
I rebased the MR to stable (v2.104.1-2-g5693cbcdd0), compiled it and tested it against my example. Compiles now without error and produces senseful code.