[cfe-dev] vector function return type

John McCall rjmccall at apple.com
Wed Dec 2 19:20:47 PST 2009

On Dec 2, 2009, at 6:34 PM, John Thompson wrote:

> I'm looking at bug 5650 about using vector return types on functions, which is kind of difficult, not knowing all the ramifications of the type system.
> For example, I need to change the return type of a function declaration, but there aren't any accessors for that.  Is that because it's complicated?

Yes.  Among other problems, the redeclaration logic will be completely wrong if you take a fully-formed function declaration and change its type.  You really need to find the attribute before building the declaration, or at least before doing redeclaration checks on it.

Meta-question:  are we sure we want to allow this syntax?  Is this a gcc compatibility issue?  Because gcc's habit of pushing attributes from decls to random component types is already really bogus, and I'm hesitant to add to that when there's a perfectly reasonable solution (typedef the vector type) already.

> For example, since the QualType can apparently point to something, is that allocated storage, such that it would leak if I just assigned to it, or is the memory managed elsewhere?  Sorry, I probably should just study it some more.

Types are immutable;  the ASTContext uniques types based on their components, and then the type object lives forever as part of the ASTContext.  So you don't have to worry about leaking memory, but you also won't be able to naively modify types like this.


More information about the cfe-dev mailing list