www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22182] New: importC: Error: expression expected, not `)` when

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

          Issue ID: 22182
           Summary: importC: Error: expression expected, not `)` when
                    casting pointer with redundant parens.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

The following fails to compile:

typedef struct Bar { int x; } Bar;

int foo(Bar* b){
    return ((Bar*)(b))->x;
    }

int main(){
    Bar b = {3};
    return foo(&b);
    }

The first relevant error is:
bar.c(4): Error: expression expected, not `)`

The `b` in the expression `((Bar*)(b))->x` has a redundant set of parentheses
around it. Removing them it compiles fine.

This pattern comes up a lot in the Python headers.

--
Aug 05