www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22067] New: importC: cast-expression accepted as lvalue in

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

          Issue ID: 22067
           Summary: importC: cast-expression accepted as lvalue in
                    assignment-expression
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

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

--
Jun 22