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
79967996 toplevel array or the last member of the toplevel struct */
79977997
79987998 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+
79998004 /* If the base type itself was an array type of unspecified size
80008005 (like in 'typedef int arr[]; arr x = {1};') then we will
80018006 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
463463 #error \123\\
464464 456
465465
466+#elif defined test_error_incomplete_type
467+struct A;
468+void f(struct A *);
469+
470+int main()
471+{
472+ f(&(struct A){});
473+}
474+
475+struct A {
476+ int x;
477+};
478+
466479 #endif
tests/tests2/60_errors_and_warnings.expect+4−1
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 [returns 1]
2424
2525 [test_61_undefined_enum]
26−60_errors_and_warnings.c:46: error: unknown type size
26+60_errors_and_warnings.c:46: error: initialization of incomplete type
2727
2828 [test_74_non_const_init]
2929 60_errors_and_warnings.c:49: error: initializer element is not constant
@@ -228,3 +228,6 @@ arg[1] = "Y" · 198 unmodified lines
228228
229229 [test_error_string]
230230 60_errors_and_warnings.c:464: error: #error \123\456
231+
232+[test_error_incomplete_type]
233+60_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