Bug 22067 – importC: cast-expression accepted as lvalue in assignment-expression

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-22T13:17:05Z
Last change time
2021-06-24T12:23:30Z
Keywords
accepts-invalid, ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2021-06-22T13:17:05Z
This isn't valid assignment as per C11 6.5.16. --- (int) i = 42; The grammar is: --- (6.5.16) assignment-expression: conditional-expression unary-expression assignment-operator assignment-expression (6.5.3) unary-expression: postfix-expression ++ unary-expression -- unary-expression unary-operator cast-expression sizeof unary-expression sizeof ( type-name ) _Alignof ( type-name ) (6.5.2) postfix-expression: primary-expression postfix-expression [ expression ] postfix-expression ( argument-expression-list(opt) ) postfix-expression . identifier postfix-expression -> identifier postfix-expression ++ postfix-expression -- ( type-name ) { initializer-list } ( type-name ) { initializer-list , } --- However, currently unary-expression and cast-expression are conflated in the parser, where they should really be separate functions. --- (6.5.4) cast-expression: unary-expression ( type-name ) cast-expression
Comment #1 by ibuclaw — 2021-06-22T14:12:51Z
DMD accepts any conditional expression on the LHS and diagnose the invalid lvalue rather than producing a syntax error. So the issue is that this isn't detected during semantic, unlike issue 22068 (though we could also move that to semantic too to for a consistent error message).
Comment #2 by ibuclaw — 2021-06-22T18:05:28Z
Actually, the list of valid lvalues in C is so simple, we can do a first pass in the parser without having to go through semantic. - CompoundLiteralExp - StringExp - PtrExp - ArrayExp - IdentifierExp - DotIdExp (if e1 is an lvalue)
Comment #3 by ibuclaw — 2021-06-22T18:06:05Z
(In reply to Iain Buclaw from comment #2) > Actually, the list of valid lvalues in C is so simple, we can do a first > pass in the parser without having to go through semantic. Semantic can deal with more complicated matters, such as const.
Comment #4 by dlang-bot — 2021-06-22T22:17:40Z
@ibuclaw created dlang/dmd pull request #12736 "fix Issue 22067 - importC: cast-expression accepted as lvalue in assignment-expression" fixing this issue: - fix Issue 22067 - importC: cast-expression accepted as lvalue in assignment-expression https://github.com/dlang/dmd/pull/12736
Comment #5 by dlang-bot — 2021-06-24T12:23:30Z
dlang/dmd pull request #12736 "fix Issue 22067 - importC: cast-expression accepted as lvalue in assignment-expression" was merged into master: - 41b50c9eebc999a9b28d8301cb2e2c79e806559c by Iain Buclaw: fix Issue 22067 - importC: cast-expression accepted as lvalue in assignment-expression https://github.com/dlang/dmd/pull/12736