issue a warning if returning the address of a local variable
[cparser] / type.c
diff --git a/type.c b/type.c
index 2c57f89..ddfb8d0 100644 (file)
--- a/type.c
+++ b/type.c
@@ -243,6 +243,7 @@ static void print_compound_type(const compound_type_t *type)
 
 static void print_typedef_type_pre(const typedef_type_t *const type)
 {
+       print_type_qualifiers(type->type.qualifiers);
        fputs(type->declaration->symbol->string, out);
 }
 
@@ -688,7 +689,7 @@ bool pointers_compatible(const type_t *type1, const type_t *type2)
 
 type_t *skip_typeref(type_t *type)
 {
-       unsigned qualifiers = type->base.qualifiers;
+       unsigned qualifiers = TYPE_QUALIFIER_NONE;
 
        while(true) {
                switch(type->kind) {
@@ -717,6 +718,16 @@ type_t *skip_typeref(type_t *type)
                break;
        }
 
+       if (qualifiers != TYPE_QUALIFIER_NONE) {
+               type_t *const copy     = duplicate_type(type);
+               copy->base.qualifiers |= qualifiers;
+
+               type = typehash_insert(copy);
+               if (type != copy) {
+                       obstack_free(type_obst, copy);
+               }
+       }
+
        return type;
 }