D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23066 - importC: cannot initialize char array with string literal of different length
Summary: importC: cannot initialize char array with string literal of different length
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, pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2022-04-28 06:48 UTC by duser
Modified: 2022-05-15 18:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description duser 2022-04-28 06:48:56 UTC
char s1[2] = "toolong"; // Error: cannot implicitly convert expression `"toolong"` of type `char[8]` to `char[2]`
char s2[50] = "tooshort"; // ok
void fn()
{
	char s3[2] = "toolong"; // Error: mismatched array lengths, 2 and 8
	char s4[50] = "tooshort"; // Error: mismatched array lengths, 50 and 9
}

these worked before https://github.com/dlang/dmd/pull/14027
Comment 1 Walter Bright 2022-04-30 04:05:45 UTC
char s1[2] = "toolong"; // gcc and clang give a warning on this, dmc gives error

char s2[50] = "tooshort"; // well, that should work

C11 6.7.9-2 says: No initializer shall attempt to provide a value for an object not contained within the entity
being initialized.

I interpret that as the s1 example should be an error.
Comment 2 Dlang Bot 2022-04-30 22:05:09 UTC
@WalterBright created dlang/dmd pull request #14046 "fix Issue 23066 - importC: cannot initialize char array with string l…" fixing this issue:

- fix Issue 23066 - importC: cannot initialize char array with string literal of different length

https://github.com/dlang/dmd/pull/14046
Comment 3 Dlang Bot 2022-05-06 07:13:57 UTC
dlang/dmd pull request #14046 "fix Issue 23066 - importC: cannot initialize char array with string l…" was merged into stable:

- 5a55e369dbd8fafa26b6cfbb4627b8d24f5d31bb by Walter Bright:
  fix Issue 23066 - importC: cannot initialize char array with string literal of different length

https://github.com/dlang/dmd/pull/14046
Comment 4 Dlang Bot 2022-05-15 18:43:57 UTC
dlang/dmd pull request #14130 "merge stable" was merged into master:

- fbe7bf2a7e2ba8e6e44b3a641b2a7b61d4869d64 by Walter Bright:
  fix Issue 23066 - importC: cannot initialize char array with string literal of different length (#14046)

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