www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - =?UTF-8?B?W0lzc3VlIDIzNjk1XSBOZXc6IGNvbXBpbGFibGUvY3Rlc3RzMi5j?=

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

          Issue ID: 23695
           Summary: compilable/ctests2.c:131:14: error: expected ‘;’
                    before ‘b’
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

When compiling the test with `gcc -std=c11 -fsyntax-only`

Original test content:
```
/*************************************************/
// typeof()

void testTypeof(void)
{
    // general declarations
    short a;
    _Static_assert(sizeof(a) == sizeof(short), "1");

    typeof(a) b;
    _Static_assert(sizeof(b) == sizeof(short), "2");

    typeof(short) c;
    _Static_assert(sizeof(c) == sizeof(short), "3");

    typeof(a + 1) d;
    _Static_assert(sizeof(d) == sizeof(int), "4"); // promoted

    typeof(a += 1) e;
    _Static_assert(sizeof(e) == sizeof(short), "5");

    typeof(1, 1) f;
    _Static_assert(sizeof(f) == sizeof(int), "6");

    typeof(_Generic(1, default: 0)) g;
    _Static_assert(sizeof(g) == sizeof(int), "7");

    const typeof(a) h = (typeof(a))0;
    _Static_assert(sizeof(h) == sizeof(short), "8");

    typeof(const short) i = h;
    _Static_assert(sizeof(i) == sizeof(short), "9");


    // function parameters
    typeof(a) fun(typeof(a), typeof(h));
    fun(a, h);
    _Static_assert(sizeof(fun(a, h)) == sizeof(short), "10");


    // aggregate fields
    struct Foo { typeof(a) x; };
    typeof(((struct Foo){0}).x) fa;
    _Static_assert(sizeof(fa) == sizeof(short), "11");


    // typedefs
    typedef short Bar;
    Bar ta;
    _Static_assert(sizeof(ta) == sizeof(short), "12");

    typeof(ta) tb;
    _Static_assert(sizeof(tb) == sizeof(short), "13");

    typeof(Bar) tc;
    _Static_assert(sizeof(tc) == sizeof(short), "14");


    // pointers
    typeof(&a) pa;
    _Static_assert(sizeof(pa) == sizeof(void*), "15");

    typeof(*pa) pb;
    _Static_assert(sizeof(pb) == sizeof(short), "16");
}

short testTypeofA;
const typeof(testTypeofA) testTypeofB = 0;
_Static_assert(sizeof(testTypeofB) == sizeof(short), "17");

/*************************************************/
```
```

Errors and warnings combined:

compilable/ctests2.c: In function ‘testTypeof’:
compilable/ctests2.c:131:5: warning: implicit declaration of function
‘typeof’;
did you mean ‘testTypeof’? [-Wimplicit-function-declaration]
  131 |     typeof(a) b;
      |     ^~~~~~
      |     testTypeof
compilable/ctests2.c:131:14: error: expected ‘;’ before ‘b’
  131 |     typeof(a) b;
      |              ^~
      |              ;
compilable/ctests2.c:132:5: error: static assertion failed: "2"
  132 |     _Static_assert(sizeof(b) == sizeof(short), "2");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:134:12: error: expected expression before ‘short’
  134 |     typeof(short) c;
      |            ^~~~~
compilable/ctests2.c:134:18: error: expected ‘;’ before ‘c’
  134 |     typeof(short) c;
      |                  ^~
      |                  ;
compilable/ctests2.c:135:27: error: ‘c’ undeclared (first use in this
function)
  135 |     _Static_assert(sizeof(c) == sizeof(short), "3");
      |                           ^
compilable/ctests2.c:135:27: note: each undeclared identifier is reported only
once for each function it appears in
compilable/ctests2.c:135:20: error: expression in static assertion is not an
integer
  135 |     _Static_assert(sizeof(c) == sizeof(short), "3");
      |                    ^~~~~~
compilable/ctests2.c:137:18: error: expected ‘;’ before ‘d’
  137 |     typeof(a + 1) d;
      |                  ^~
      |                  ;
compilable/ctests2.c:138:27: error: ‘d’ undeclared (first use in this
function)
  138 |     _Static_assert(sizeof(d) == sizeof(int), "4"); // promoted
      |                           ^
compilable/ctests2.c:138:20: error: expression in static assertion is not an
integer
  138 |     _Static_assert(sizeof(d) == sizeof(int), "4"); // promoted
      |                    ^~~~~~
compilable/ctests2.c:140:19: error: expected ‘;’ before ‘e’
  140 |     typeof(a += 1) e;
      |                   ^~
      |                   ;
compilable/ctests2.c:141:27: error: ‘e’ undeclared (first use in this
function)
  141 |     _Static_assert(sizeof(e) == sizeof(short), "5");
      |                           ^
compilable/ctests2.c:141:20: error: expression in static assertion is not an
integer
  141 |     _Static_assert(sizeof(e) == sizeof(short), "5");
      |                    ^~~~~~
compilable/ctests2.c:143:17: error: expected ‘;’ before ‘f’
  143 |     typeof(1, 1) f;
      |                 ^~
      |                 ;
compilable/ctests2.c:144:27: error: ‘f’ undeclared (first use in this
function)
  144 |     _Static_assert(sizeof(f) == sizeof(int), "6");
      |                           ^
compilable/ctests2.c:144:20: error: expression in static assertion is not an
integer
  144 |     _Static_assert(sizeof(f) == sizeof(int), "6");
      |                    ^~~~~~
compilable/ctests2.c:146:36: error: expected ‘;’ before ‘g’
  146 |     typeof(_Generic(1, default: 0)) g;
      |                                    ^~
      |                                    ;
compilable/ctests2.c:147:27: error: ‘g’ undeclared (first use in this
function)
  147 |     _Static_assert(sizeof(g) == sizeof(int), "7");
      |                           ^
compilable/ctests2.c:147:20: error: expression in static assertion is not an
integer
  147 |     _Static_assert(sizeof(g) == sizeof(int), "7");
      |                    ^~~~~~
compilable/ctests2.c:149:11: warning: return type defaults to ‘int’
[-Wimplicit-int]
  149 |     const typeof(a) h = (typeof(a))0;
      |           ^~~~~~
compilable/ctests2.c:149:11: error: static declaration of ‘typeof’ follows
non-static declaration
compilable/ctests2.c:131:5: note: previous implicit declaration of ‘typeof’
with type ‘int()’
  131 |     typeof(a) b;
      |     ^~~~~~
compilable/ctests2.c: In function ‘typeof’:
compilable/ctests2.c:149:21: error: expected declaration specifiers before
‘h’
  149 |     const typeof(a) h = (typeof(a))0;
      |                     ^
compilable/ctests2.c:150:5: error: expected declaration specifiers before
‘_Static_assert’
  150 |     _Static_assert(sizeof(h) == sizeof(short), "8");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:152:5: error: expected declaration specifiers before
‘typeof’
  152 |     typeof(const short) i = h;
      |     ^~~~~~
compilable/ctests2.c:153:5: error: expected declaration specifiers before
‘_Static_assert’
  153 |     _Static_assert(sizeof(i) == sizeof(short), "9");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:157:5: error: expected declaration specifiers before
‘typeof’
  157 |     typeof(a) fun(typeof(a), typeof(h));
      |     ^~~~~~
compilable/ctests2.c:158:5: error: expected declaration specifiers before
‘fun’
  158 |     fun(a, h);
      |     ^~~
compilable/ctests2.c:159:5: error: expected declaration specifiers before
‘_Static_assert’
  159 |     _Static_assert(sizeof(fun(a, h)) == sizeof(short), "10");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:163:18: error: expected specifier-qualifier-list before
‘typeof’
  163 |     struct Foo { typeof(a) x; };
      |                  ^~~~~~
compilable/ctests2.c:163:5: warning: empty declaration
  163 |     struct Foo { typeof(a) x; };
      |     ^~~~~~
compilable/ctests2.c:164:5: error: expected declaration specifiers before
‘typeof’
  164 |     typeof(((struct Foo){0}).x) fa;
      |     ^~~~~~
compilable/ctests2.c:164:28: error: expected declaration specifiers before
‘)’
token
  164 |     typeof(((struct Foo){0}).x) fa;
      |                            ^
compilable/ctests2.c:165:5: error: expected declaration specifiers before
‘_Static_assert’
  165 |     _Static_assert(sizeof(fa) == sizeof(short), "11");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:169:19: error: storage class specified for parameter
‘Bar’
  169 |     typedef short Bar;
      |                   ^~~
compilable/ctests2.c:170:5: error: expected declaration specifiers before
‘Bar’
  170 |     Bar ta;
      |     ^~~
compilable/ctests2.c:171:5: error: expected declaration specifiers before
‘_Static_assert’
  171 |     _Static_assert(sizeof(ta) == sizeof(short), "12");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:173:5: error: expected declaration specifiers before
‘typeof’
  173 |     typeof(ta) tb;
      |     ^~~~~~
compilable/ctests2.c:174:5: error: expected declaration specifiers before
‘_Static_assert’
  174 |     _Static_assert(sizeof(tb) == sizeof(short), "13");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:176:5: error: expected declaration specifiers before
‘typeof’
  176 |     typeof(Bar) tc;
      |     ^~~~~~
compilable/ctests2.c:177:5: error: expected declaration specifiers before
‘_Static_assert’
  177 |     _Static_assert(sizeof(tc) == sizeof(short), "14");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:181:5: error: expected declaration specifiers before
‘typeof’
  181 |     typeof(&a) pa;
      |     ^~~~~~
compilable/ctests2.c:182:5: error: expected declaration specifiers before
‘_Static_assert’
  182 |     _Static_assert(sizeof(pa) == sizeof(void*), "15");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:184:5: error: expected declaration specifiers before
‘typeof’
  184 |     typeof(*pa) pb;
      |     ^~~~~~
compilable/ctests2.c:185:5: error: expected declaration specifiers before
‘_Static_assert’
  185 |     _Static_assert(sizeof(pb) == sizeof(short), "16");
      |     ^~~~~~~~~~~~~~
compilable/ctests2.c:186:1: error: expected declaration specifiers before
‘}’
token
  186 | }
      | ^
compilable/ctests2.c:189:27: error: expected ‘=’, ‘,’, ‘;’,
‘asm’ or
‘__attribute__’ before ‘testTypeofB’
  189 | const typeof(testTypeofA) testTypeofB = 0;
      |                           ^~~~~~~~~~~
compilable/ctests2.c:190:1: error: expected declaration specifiers before
‘_Static_assert’
  190 | _Static_assert(sizeof(testTypeofB) == sizeof(short), "17");
      | ^~~~~~~~~~~~~~
compilable/ctests2.c:149:11: warning: type of ‘a’ defaults to ‘int’
[-Wimplicit-int]
  149 |     const typeof(a) h = (typeof(a))0;
      |           ^~~~~~
compilable/ctests2.c:188:7: error: declaration for parameter ‘testTypeofA’
but
no such parameter
  188 | short testTypeofA;
      |       ^~~~~~~~~~~
compilable/ctests2.c:169:19: error: declaration for parameter ‘Bar’ but no
such
parameter
  169 |     typedef short Bar;
      |                   ^~~
compilable/ctests2.c:193: error: expected ‘{’ at end of input
compilable/ctests2.c: In function ‘testTypeof’:
compilable/ctests2.c:190:1: error: expected declaration or statement at end of
input
  190 | _Static_assert(sizeof(testTypeofB) == sizeof(short), "17");
      | ^~~~~~~~~~~~~~

--
Feb 12 2023