This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/65685] Reducing alignment with alignas should be rejected
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 23 Jan 2016 18:09:16 +0000
- Subject: [Bug c++/65685] Reducing alignment with alignas should be rejected
- Auto-submitted: auto-generated
- References: <bug-65685-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65685
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
Known to fail| |4.5.3, 4.8.3, 4.9.3, 5.3.0,
| |6.0
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Still fails with the latest trunk and always has.
Below is a slightly modified test case to compare the behavior between C++11
(using alignas), C11 (using _Alignas), and prior standards (using GCC's
__attribute__ aligned). As expected, GCC in C11 mode rejects the _Alignas
specifier iB with the error below:
u.cpp:10:32: error: â_Alignasâ specifiers cannot reduce alignment of âaâ
Both gcc and g++ silently accept but ignore __attribute__ aligned in B (it
would be nice if they issued a warning to point that out).
Finally, as noted, g++ in C++11 mode silently accepts the code:
$ cat u.cpp && /home/msebor/build/gcc-trunk-svn/gcc/xgcc
-B/home/msebor/build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -std=c++11
-xc++ u.cpp
#if __cplusplus >= 201103L
# define Align(N) alignas (N)
#elif __STDC_VERSION__ >= 201112L
# define Align(N) _Alignas (N)
#else
# define Align(N) __attribute__ ((aligned (N)))
#endif
typedef struct A { Align (8) char c; } A;
typedef struct B { Align (1) A a; } B;
#define A(e) typedef char Assert [1 - 2 * !(e)]
A (__alignof__ (A) == 8);
A (__alignof__ (B) == 8);