D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22072 - importC: Error: compound literal is not an lvalue and cannot be modified
Summary: importC: Error: compound literal is not an lvalue and cannot be modified
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: ImportC, rejects-valid
Depends on:
Blocks:
 
Reported: 2021-06-22 19:42 UTC by Iain Buclaw
Modified: 2022-09-20 04:53 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 Iain Buclaw 2021-06-22 19:42:39 UTC
It can be used as an lvalue in an assignment in C
"""
6.5.2.5-5
The  value  of  the  compound  literal  is  that  of  an  unnamed  object  initialized  by  the initializer  list.  If  the  compound  literal  occurs  outside  the  body  of  a  function,  the  object has  static  storage  duration;  otherwise,  it  has  automatic  storage  duration  associated  with the enclosing block.
"""

Reduced test:
---
struct S { int a; int b; };
void test()
{
    (struct S) { 1, 2 } = (struct S) { 3, 4 };
}
Comment 1 Walter Bright 2022-09-20 04:53:11 UTC
This compiles without complaint in master. The generated asm looks correct.