Issue 23662 - ImportC bad handling of enum arguments for a function
Summary: ImportC bad handling of enum arguments for a function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC
Depends on:
Blocks:
 
Reported: 2023-01-30 23:10 UTC by Walter Bright
Modified: 2023-06-28 14:09 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2023-01-30 23:10:32 UTC
From Dmytro Katyukha <firemage.dima@gmail.com>:

It seems that ImportC does not allow to pass enums declared with typedef but without tag to function that receives enum as one of argument


## The code snippets:

```c
// testlib.c
typedef enum /*enum_test_1_t*/ {
    E_TEST_1_ITEM_1 = 1,
    E_TEST_1_ITEM_2,
} enum_test_1_t;

int some_func(enum_test_1_t val) {
    return val;
}
```

```d
//test.d
import testlib;

void main(string[] args) {
    enum_test_1_t val1 = E_TEST_1_ITEM_1;

    some_func(E_TEST_1_ITEM_1);
}
```

## Attempt to compile produce following output

```
dmd test.d testlib.c
test.d(6): Error: function `testlib.some_func(__tag2 val)` is not callable using argument types `(__anonymous)`
test.d(6):        cannot pass argument `E_TEST_1_ITEM_1` of type `__anonymous` to parameter `__tag2 val`
```
Comment 1 Dlang Bot 2023-02-02 21:21:48 UTC
@katyukha created dlang/dmd pull request #14859 "Fix Issue 23662: ImportC bad handling of enum arguments for a function" mentioning this issue:

- Added testcase for Issue 23662
  
  See: https://issues.dlang.org/show_bug.cgi?id=23662

- [FIX] Issue 23662

https://github.com/dlang/dmd/pull/14859
Comment 2 Dlang Bot 2023-02-09 10:50:23 UTC
dlang/dmd pull request #14859 "Fix Issue 23662: ImportC bad handling of enum arguments for a function" was merged into stable:

- 26358e7106349f319f94f28bd152ee4b9614e63f by Dmytro Katyukha:
  Added testcase for Issue 23662
  
  See: https://issues.dlang.org/show_bug.cgi?id=23662

- 5e72b01d56594288a6c43683a06eccb61d74df7b by Dmytro Katyukha:
  Fix Issue 23662

https://github.com/dlang/dmd/pull/14859
Comment 3 Dlang Bot 2023-02-13 03:29:12 UTC
dlang/dmd pull request #14875 "merge stable" was merged into master:

- 582dd6c1a1c8f2fc07498c3787dd5b878dac79b3 by Dmytro Katyukha:
  Fix Issue 23662: ImportC bad handling of enum arguments for a function (#14859)
  
  * Added testcase for Issue 23662
  
  See: https://issues.dlang.org/show_bug.cgi?id=23662
  
  * Fix Issue 23662

https://github.com/dlang/dmd/pull/14875