| 1 |
// PR c++/7046 |
| 2 |
|
| 3 |
extern "C" int printf (const char *, ...); |
| 4 |
|
| 5 |
#pragma pack(4) |
| 6 |
|
| 7 |
template <typename X > |
| 8 |
struct T |
| 9 |
{ |
| 10 |
char x1; /* Usually 3 padding bytes are added after x1 member. */ |
| 11 |
int x2; |
| 12 |
}; |
| 13 |
|
| 14 |
template <class T> |
| 15 |
int f() |
| 16 |
{ |
| 17 |
struct A { char i1; int i2; }; |
| 18 |
return sizeof (A); |
| 19 |
} |
| 20 |
|
| 21 |
#pragma pack(1) |
| 22 |
template struct T<int>; /* T<int> is instantiated here */ |
| 23 |
template int f<int>(); |
| 24 |
|
| 25 |
#pragma pack(4) |
| 26 |
template struct T<float>; /* T<float> is required here */ |
| 27 |
template int f<double>(); |
| 28 |
|
| 29 |
int main() |
| 30 |
{ |
| 31 |
printf("sizeof T<int> = %d\n", sizeof(T<int>)); |
| 32 |
printf("sizeof T<float> = %d\n", sizeof(T<float>)); |
| 33 |
printf("f<int>() = %d\n", f<int>()); |
| 34 |
printf("f<float>() = %d\n", f<float>()); |
| 35 |
return (sizeof(T<int>) != sizeof(T<float>) |
| 36 |
|| f<int>() != f<float>()); |
| 37 |
} |