c++/10332: Template classes are not instantiated correctly in presense of #pragma pack()

Igor A. Goussarov igusarov@akella.com
Mon Apr 14 09:59:00 GMT 2003


Momchil Velikov wrote:
 >>>>>>"Igor" == Igor A Goussarov <igusarov@akella.com> writes:
 >     Igor> Momchil Velikov wrote:
 >     >> What is the scope of #pragma pack ?
 >
 >     Igor>     Apparently, from the line it is encountered at till the 
end of
 >     Igor> translation unit or till the next #pragma pack.
 >
 > In that case holding it in a global variable looks appropriate, no ?

    Up to a certain degree, yes. The concept of "packing" is applied to 
structures, thus the packing size is a property of each structure. 
Holding it in a global variable is justifiable only if there's 
absolutely no chance that this variable could potentially be altered 
before it is used to create an internal compiler representation of the 
structure in question. I grant that C plain structures are 
"instantiated" immediately at the point of their definition. C++ 
templates are not.
    The compiler still have to store the last packing size in a global 
var (or a stack, to support #pragma push/pop). But as soon as a struct 
definition is encountered (whether a template or not), the value of that 
global var should've been copied to that structure description. And the 
compiler should later use the value from the structure description 
rather then from the global var. In other words, the global var only 
stores the current packing size and is used _solely_ to initialize the 
packing size of each new defined struct.
    As Loren has mentioned, #pragma pack came from C compiler, and 
probably its interference with C++ entities was not fully considered...
    By now, I'm most interested in figuring out the point of view of the 
gcc developers: do you tend to think that the current interference of 
#pragma pack and templates is an undocumented feature or an incorrect 
behaviour?

Best Regards,
Igor



More information about the Gcc-bugs mailing list