public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48138] New: __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode.
@ 2011-03-15 18:18 jyasskin at gcc dot gnu.org
2011-06-20 2:21 ` [Bug c++/48138] " jason at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2011-03-15 18:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48138
Summary: __attribute__((aligned)) should give an error when
applied to a typedef or template parameter, at least
in C++0x mode.
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jyasskin@gcc.gnu.org
In the C++0x draft, [dcl.align] says:
"An alignment-specifier may be applied to a variable or to a class
data member, but it shall not be applied to a bit-field, a function
parameter, the formal parameter of a catch clause (15.3), or a
variable declared with the register storage class specifier. An
alignment-specifier may also be applied to the declaration of a class
or enumeration type."
This does not allow its use on a typedef or next to a typename template
parameter. It might make sense for gcc to support that as an extension, but
gcc's current behavior is not what people expect that extension to do:
$ cat test.cc
#include <iostream>
#define ALIGNED(x) __attribute__((aligned(x)))
struct Char15 {
char x[15];
} ALIGNED(8);
template<typename T>
void print_type_alignment(const T&) {
struct { char c; T t; } s;
std::cout << sizeof(T) << ' ' << ((char*)&s.t - (char*)&s.c) << '\n';
}
int main() {
typedef char unaligned[15];
typedef char aligned[15] ALIGNED(8);
unaligned x[10];
aligned y[10];
Char15 c15[10];
std::cout << sizeof(unaligned) << ' ' << sizeof(x) << '\n';
std::cout << sizeof(aligned) << ' ' << sizeof(y) << '\n';
std::cout << sizeof(Char15) << ' ' << sizeof(c15) << '\n';
aligned z ALIGNED(8);
print_type_alignment<unaligned ALIGNED(8)>(z);
}
$ g++-mp-4.6 -std=gnu++0x test.cc && ./a.out
15 150
15 152
16 160
15 1
Note that the alignment on the typedef applies to the final variable, not the
defined type, which means that interior members of arrays of the defined type
have an unexpected alignment. This has been reported several times before
(PR43798, PR47557, PR12742, PR42098), but the core problem seems to be that
alignments on typedefs aren't supported.
__attribute__((aligned)) on template arguments seems to have no effect at all.
$ g++-mp-4.6 -v
Using built-in specs.
COLLECT_GCC=g++-mp-4.6
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/lto-wrapper
Target: x86_64-apple-darwin10
Configured with: ../gcc-4.6-20110305/configure --prefix=/opt/local
--build=x86_64-apple-darwin10 --enable-languages=c,c++,objc,obj-c++
--libdir=/opt/local/lib/gcc46 --includedir=/opt/local/include/gcc46
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.6 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.6
--with-gxx-include-dir=/opt/local/include/gcc46/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --enable-stage1-checking
--disable-multilib --enable-fully-dynamic-string
Thread model: posix
gcc version 4.6.0 20110305 (experimental) (GCC)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/48138] __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode.
2011-03-15 18:18 [Bug c++/48138] New: __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode jyasskin at gcc dot gnu.org
@ 2011-06-20 2:21 ` jason at gcc dot gnu.org
2011-06-20 14:42 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20 2:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48138
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2011.06.20 02:20:52
CC| |jason at gcc dot gnu.org
AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/48138] __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode.
2011-03-15 18:18 [Bug c++/48138] New: __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode jyasskin at gcc dot gnu.org
2011-06-20 2:21 ` [Bug c++/48138] " jason at gcc dot gnu.org
@ 2011-06-20 14:42 ` jason at gcc dot gnu.org
2011-06-21 2:25 ` jason at gcc dot gnu.org
2011-06-21 2:26 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20 14:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48138
--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-20 14:40:27 UTC ---
Author: jason
Date: Mon Jun 20 14:40:19 2011
New Revision: 175215
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175215
Log:
PR c++/48138
* tree.c (strip_typedefs): Use build_aligned_type.
Added:
trunk/gcc/testsuite/g++.dg/ext/attr-aligned01.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/tree.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/48138] __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode.
2011-03-15 18:18 [Bug c++/48138] New: __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode jyasskin at gcc dot gnu.org
2011-06-20 2:21 ` [Bug c++/48138] " jason at gcc dot gnu.org
2011-06-20 14:42 ` jason at gcc dot gnu.org
@ 2011-06-21 2:25 ` jason at gcc dot gnu.org
2011-06-21 2:26 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-21 2:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48138
--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-21 02:24:12 UTC ---
Author: jason
Date: Tue Jun 21 02:24:09 2011
New Revision: 175236
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175236
Log:
PR c++/48138
* pt.c (canonicalize_type_argument): New.
(convert_template_argument, unify): Use it.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/g++.dg/ext/attr-aligned01.C
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/48138] __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode.
2011-03-15 18:18 [Bug c++/48138] New: __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode jyasskin at gcc dot gnu.org
` (2 preceding siblings ...)
2011-06-21 2:25 ` jason at gcc dot gnu.org
@ 2011-06-21 2:26 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-21 2:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48138
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-21 02:25:34 UTC ---
We now warn about ignored attributes on type arguments to class templates, but
not yet for functions. Unassigning for now.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-06-21 2:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-15 18:18 [Bug c++/48138] New: __attribute__((aligned)) should give an error when applied to a typedef or template parameter, at least in C++0x mode jyasskin at gcc dot gnu.org
2011-06-20 2:21 ` [Bug c++/48138] " jason at gcc dot gnu.org
2011-06-20 14:42 ` jason at gcc dot gnu.org
2011-06-21 2:25 ` jason at gcc dot gnu.org
2011-06-21 2:26 ` jason at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).