[Clang][C] Assigning to struct with const member wrongly allowed
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```c
int main() {
struct {
struct {
const int i;
} sa[3];
} s1, s2 = {};
s1 = s2; // expected error
}
```
https://c.godbolt.org/z/sn5zYeKc3
N3886 6.3.3.1:
> A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete
type, does not have a const-qualified type, and if it is a structure or union, does not have any
member (including, recursively, any member or element of all contained aggregates or unions) with
a const-qualified type.
If I understand it right, the innermost `const int` member should be recursively considered during modifiable lvalue determination.
Possibly related: https://github.com/llvm/llvm-project/issues/48099
Contributor guide
Research direction
Reproduce the behavior with the C snippet and compare the compiler's diagnostic with the modifiable-lvalue rule quoted in the issue. Locate Clang's C semantic checking for structure assignment and inspect existing related tests, if present. Done means the assignment is rejected when a nested aggregate contains a const member, with regression coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100