www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22560] New: ImportC: extra semicolon not allowed outside of


          Issue ID: 22560
           Summary: ImportC: extra semicolon not allowed outside of
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

Compilation fails if an extra semicolon is encountered outside of a function.

For example:

// semi.c
; // semi.c(1): Error: identifier or `(` expected
int main(){return 0;}

This is technically correct, but sometimes headers end up with extra semicolons
at file scope after pre-processing if conditional type declarations are
incorrectly guarded. For example, a header might use a function-like macro to
declare a type, conditionally defining it to expand to nothing. Then they
incorrectly put a semicolon after the function like macro. For example:

#define DECLARE(name) struct name
#define DECLARE(name)

DECLARE(name); // this semicolon is incorrect if SOME_CONDITION is false

Some headers on macOS have this incorrect pattern. GCC and clang both allow the
extra semicolon at file scope.

Dec 02 2021