Hi tcc folks,

I think I sent a premature version of this mail earlier. If so, please
forgive me for it.

In its current version tcc allows using incomplete types inside
structures/unions.

Therefore the following codes incorrectly compile in tcc:


struct myFirstStruct; //incomplete type

struct mySecondStruct{
    struct myFirstStruct field;
};

// or even the following circular structure

struct mySecondStruct{
    struct mySecondStruct field;
};


Below is a tentative patch to correct this behaviour.
Thanks and keep up the good work.
--
diff --git a/tccgen.c b/tccgen.c
index 0f0aac5..af8140a 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2824,6 +2824,9 @@ static void struct_decl(CType *type, int u, int tdef)
                         type_decl(&type1, &ad, &v, TYPE_DIRECT |
TYPE_ABSTRACT);
                         if (v == 0 && (type1.t & VT_BTYPE) != VT_STRUCT)
                             expect("identifier");
+                       if (type_size(&type1, &align) < 0)
+                            tcc_error("field '%s' has incomplete type",
+                                  get_tok_str(v, NULL));
                         if ((type1.t & VT_BTYPE) == VT_FUNC ||
                             (type1.t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN
| VT_INLINE)))
                             tcc_error("invalid type for '%s'",

Attachment: incomplete_types.patch
Description: Binary data

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to