[Issue 22877] importC: wrong sizeof for string literal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 26 08:22:22 UTC 2022


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

Steven Dwy <me at yoplitein.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |me at yoplitein.net
         Resolution|FIXED                       |---

--- Comment #3 from Steven Dwy <me at yoplitein.net> ---
With this fix sizeof an address of a string literal is also the length of the
string:
```
const int s1 = sizeof("aa");
_Static_assert(s1 == 3, "");
const int s2 = sizeof(&"aa");
_Static_assert(s2 == sizeof(void*), ""); // fails
```

Additionally, the following invalid code is now accepted:
```
char(**s1)[3] = &(&"aa");
char(***s2)[3] = &(&(&"aa"));
// and so on
```

--


More information about the Digitalmars-d-bugs mailing list