[Issue 22560] New: ImportC: extra semicolon not allowed outside of functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 3 01:01:34 UTC 2021


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

          Issue ID: 22560
           Summary: ImportC: extra semicolon not allowed outside of
                    functions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dave287091 at 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:

#if SOME_CONDITION
#define DECLARE(name) struct name
#else
#define DECLARE(name)
#endif

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.

--


More information about the Digitalmars-d-bugs mailing list