[Bug c++/84194] New: fails to pack structs with template members
stsp at users dot sourceforge.net
gcc-bugzilla@gcc.gnu.org
Sat Feb 3 20:04:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84194
Bug ID: 84194
Summary: fails to pack structs with template members
Product: gcc
Version: 7.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: stsp at users dot sourceforge.net
Target Milestone: ---
Created attachment 43333
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43333&action=edit
test-case
Hello.
Attached is a fully automated test-case
for the problem. Just run "make" and it
will compile test-case with clang and with
gcc, and will compare the output:
---
$ LC_ALL=C make
clang++ -std=c++11 -o p_clng pod.cpp
g++ -std=c++11 -o p_gcc pod.cpp
pod.cpp:16:23: warning: ignoring packed attribute because of unpacked non-POD
field 'SymWrp<dhdr> lol::_n'
SymWrp<struct dhdr> _n;
^~
./tst.sh
Test FAILED (sizeof returns 6 instead of 4)
---
This is somewhat similar to bug #83732, but
in #83732 it was considered a diagnostic problem.
Unfortunately it actually produces the bad code,
which is what the test-case demonstrates.
The test code is:
---
#include <stdio.h>
#include <stdint.h>
template<typename T>
class SymWrp : public T {
public:
SymWrp() = default;
};
struct dhdr {
uint16_t dh_attr;
};
struct lol {
unsigned char _l;
SymWrp<struct dhdr> _n;
unsigned char _nj;
} __attribute__((packed));
int main()
{
printf("%zi\n", sizeof(struct lol));
return 0;
}
---
More information about the Gcc-bugs
mailing list