This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __alignof__(T) not compile time constant?


Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:

| Hi!
| 
| Can someone please look at C++/10479 and verify if the current behavior is
| intentional? Just fyi:

The root of the disease is the same as for the PR that talks about
alignment in std::basic_string. 

I promised Paolo that I'll raise the issue.  Now seems to be the time.

What is happening is that the __attribute__ machinery is designed with
C in mind, but not C++. In C++, name lookup is a key notion; in C, it is
not as important.  In C, most constants are literals; in C++ most
constants are expressions that involve named constants.  In C++, some
expressions become constant only after template instantiation.

__attribute__ is designed (at least in its current incarnation) so
that it acts like a meta-linguistic construct that directs the parser
not to apply the usual applicable name lookup semantics.  In
particular, anything in the double-parens that is not literal is
interpreted as a directive; anything in the double-parens that is not
fully processed at parsing time is interpreted as a directive.  So one
can get a bogus treatment at instantiation time.  The C++ parser
currently does not substitute into DECL_ATTRIBUTES in no useful way. 

| template <int i>
| struct foo2 {
|         float bar __attribute__((aligned(__alignof__(double))));
| };

you may also add

  template<int N>
   struct X {
      __attribute__((__aligned__(N))) char data;
   };

We need to build a list of attributes that can be applied only at
instantiation time; most importantly, one would need to allow name
lookup to find that the "N" in __aligned__(N) is the
template-parameter -- currently it thinks it is a name.  In fact, we
should apply the notion of dependent-type and dependent-value for
attributes also.  Given that they don't respect C++ usual name lookup
rules, that would be interesting...

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]