Bug#603979: g++-4.3: #pragma pack mechanism receives less error checking than attribute method
Package: g++-4.3
Version: 4.3.2-1.1
Severity: normal
As documented here:
http://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Structure_002dPacking-Pragmas.html#Structure_002dPacking-Pragmas
g++ supports using the #pragma pack syntax to forcibly pack a structure
which must be the minimum size. The alternative mechanism to specify
this is to add `__attribute__((packed))' before the final terminating
semicolon of the struct definition.
Unfortunately it seems the path for checking errors is not uniform
between the two mechanisms. The compiler complains about the
definition of struct Y (returning a reference to a field in a packed
struct is invalid) in the following program, but not the definition of
struct X.
#include <cstdlib>
#pragma pack(push, 1)
struct X {
int x;
int& operator[](size_t) { return this->x; }
};
#pragma pack(pop)
struct Y {
int x;
int& operator[](size_t) { return this->x; }
} __attribute__((packed));
If these paths are truly doing the same thing, the error message should
also apply to the first struct's definition. The exact error text is:
pack.cxx: In member function ‘int& Y::operator[](size_t)’:
pack.cxx:11: error: cannot bind packed field ‘((Y*)this)->Y::x’ to
‘int&’
-- System Information:
Debian Release: 5.0.6
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.26-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages g++-4.3 depends on:
ii gcc-4.3 4.3.2-1.1 The GNU C compiler
ii gcc-4.3-base 4.3.2-1.1 The GNU Compiler Collection (base
ii libc6 2.7-18lenny4 GNU C Library: Shared libraries
ii libgmp3c2 2:4.2.2+dfsg-3 Multiprecision arithmetic library
ii libmpfr1ldbl 2.3.1.dfsg.1-2 multiple precision floating-point
ii libstdc++6-4.3-dev 4.3.2-1.1 The GNU Standard C++ Library v3 (d
g++-4.3 recommends no packages.
Versions of packages g++-4.3 suggests:
pn g++-4.3-multilib <none> (no description available)
ii gcc-4.3-doc 4.3.2.nf1-1 documentation for the GNU compiler
pn libstdc++6-4.3-dbg <none> (no description available)
-- no debconf information
Reply to: