Bug 23714 – compilable/testcstuff1.c:213:1: error: static assertion failed: u'ab' == 0x610062

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2023-02-15T16:40:07Z
Last change time
2023-12-05T06:12:21Z
Keywords
accepts-invalid, ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw
Depends on
23689
See also
https://issues.dlang.org/show_bug.cgi?id=23689

Comments

Comment #0 by ibuclaw — 2023-02-15T16:40:07Z
When compiling the test with `gcc -std=c11 -fsyntax-only` compilable/testcstuff1.c:213:16: warning: character constant too long for its type 213 | _Static_assert(u'ab' == 0x610062, "ok"); | ^~~~~ compilable/testcstuff1.c:213:1: error: static assertion failed: "ok" 213 | _Static_assert(u'ab' == 0x610062, "ok"); | ^~~~~~~~~~~~~~ Test case: ``` _Static_assert(u'ab' == 0x610062, "ok"); ```
Comment #1 by bugzilla — 2023-12-02T02:35:08Z
It's a warning, as most C compilers will allow multi-character character constants as an extension.
Comment #2 by ibuclaw — 2023-12-02T12:19:03Z
(In reply to Walter Bright from comment #1) > It's a warning, as most C compilers will allow multi-character character > constants as an extension. The static assert fails though, which it doesn't with importC. It might suggest we're following a subtly different semantic than what C does, which may or may not be problematic in real-life projects.
Comment #3 by bugzilla — 2023-12-03T07:09:45Z
C11 6.4.4.4-11 says: "a wide character constant prefixed by the letter u or U has type char16_t or char32_t, respectively, unsigned integer types defined in the <uchar.h> header." clang gives an error for u'ab', gcc gives a warning and produces the value 0x62 for it. I suggest the best solution for ImportC is to produce the value 0x62, not 0x610062.
Comment #4 by dlang-bot — 2023-12-03T07:38:09Z
@WalterBright created dlang/dmd pull request #15878 "fix Issue 23714 - compilable/testcstuff1.c:213:1: error: static asser…" fixing this issue: - fix Issue 23714 - compilable/testcstuff1.c:213:1: error: static assertion failed: u'ab' == 0x610062 https://github.com/dlang/dmd/pull/15878
Comment #5 by dlang-bot — 2023-12-05T06:12:21Z
dlang/dmd pull request #15878 "fix Issue 23714 - compilable/testcstuff1.c:213:1: error: static asser…" was merged into master: - 77583919dd5e7ee3ce29d823a5b9c050956f6152 by Walter Bright: fix Issue 23714 - compilable/testcstuff1.c:213:1: error: static assertion failed: u'ab' == 0x610062 https://github.com/dlang/dmd/pull/15878