History

Error out for incomplete type initialisation

Rob Pilling committed 2 years ago

Commit fb164e01 parent be8f8943 files · +22 −1Browse files

Unified · Split

3 files
  1. tccgen.c +5 −0
  2. tests/tests2/60_errors_and_warnings.c +13 −0
  3. tests/tests2/60_errors_and_warnings.expect +4 −1
tccgen.c+5−0
@@ -7996,6 +7996,11 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 7995 unmodified lines
7996 toplevel array or the last member of the toplevel struct */7996 toplevel array or the last member of the toplevel struct */
7997 7997
7998 if (size < 0) {7998 if (size < 0) {
7999 // error out except for top-level incomplete arrays
8000 // (arrays of incomplete types are handled in array parsing)
8001 if (!(type->t & VT_ARRAY))
8002 tcc_error("initialization of incomplete type");
8003
7999 /* If the base type itself was an array type of unspecified size8004 /* If the base type itself was an array type of unspecified size
8000 (like in 'typedef int arr[]; arr x = {1};') then we will8005 (like in 'typedef int arr[]; arr x = {1};') then we will
8001 overwrite the unknown size by the real one for this decl.8006 overwrite the unknown size by the real one for this decl.
tests/tests2/60_errors_and_warnings.c+13−0
@@ -463,4 +463,17 @@ int main() { · 462 unmodified lines
463#error \123\\463#error \123\\
464456464456
465 465
466#elif defined test_error_incomplete_type
467struct A;
468void f(struct A *);
469
470int main()
471{
472 f(&(struct A){});
473}
474
475struct A {
476 int x;
477};
478
466#endif479#endif
tests/tests2/60_errors_and_warnings.expect+4−1
@@ -23,7 +23,7 @@ · 22 unmodified lines
23[returns 1]23[returns 1]
24 24
25[test_61_undefined_enum]25[test_61_undefined_enum]
2660_errors_and_warnings.c:46: error: unknown type size2660_errors_and_warnings.c:46: error: initialization of incomplete type
27 27
28[test_74_non_const_init]28[test_74_non_const_init]
2960_errors_and_warnings.c:49: error: initializer element is not constant2960_errors_and_warnings.c:49: error: initializer element is not constant
@@ -228,3 +228,6 @@ arg[1] = "Y" · 198 unmodified lines
228 228
229[test_error_string]229[test_error_string]
23060_errors_and_warnings.c:464: error: #error \123\45623060_errors_and_warnings.c:464: error: #error \123\456
231
232[test_error_incomplete_type]
23360_errors_and_warnings.c:472: error: initialization of incomplete type

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t