This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] Attributes on types
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: "Svein E. Seldal" <svein dot seldal at solidas dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 13 May 2004 20:04:36 +0000 (UTC)
- Subject: Re: [RFC] Attributes on types
- References: <40A3C9E9.8050807@solidas.com>
On Thu, 13 May 2004, Svein E. Seldal wrote:
> I am looking at extending gcc's features by adding the ability to
> declare attributes on types. I.e. Making persistent attributes that
> stick to the type decleration and will give warnings/errors if any
> assignments across types are made:
I believe the attribute system I implemented in
<http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00774.html> is general
enough for an attribute handler to do what you want. The "Attribute
Syntax" section of the manual specifies what it means for attributes to
appear in the different possible places in a declaration, and as far as I
know the documented semantics are the correct semantics for attributes to
have (but I now doubt it would be a good idea to change where postfix
attributes apply to as suggested there, despite the natural similarity to
some C++ syntax).
The actual attribute handlers I made as near as I could bug-compatible
with the previous code; most have not been cleaned up to be more general.
(I did look at cleaning up noreturn attributes to apply generally to
types, but there were rather a lot of TREE_THIS_VOLATILE uses to go
through to work out whether they were actually testing the nonreturning
nature of a function and should be changed to a test on its type.)
As for compatibility, both for forming composite types (e.g. in
conditional expressions) and unidirectional compatibility, some target
hooks exist but I didn't redesign them as part of table-driven attributes
and more might be needed. noreturn and const attributes work by reusing
type qualifier bits and having special code that knows that whereas a
value of type int * can be stored in a variable of type const int *, const
functions work the other way round: const functions are a subtype of
functions so you can store a const function pointer in an ordinary
function pointer variable but the other way round may be unsafe. It is a
question to be considered separately for each attribute what effect if any
it has on the type system; some attributes may work like const and
noreturn attributes (creating subtypes) while others may work as you
suggest.
Note carefully the warnings in "Attribute Syntax" about limitations of
attributes in C++. They fit less easily with the C++ language than with
C.
--
Joseph S. Myers
jsm@polyomino.org.uk