From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4338 invoked by alias); 14 Apr 2003 10:06:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 4324 invoked by uid 71); 14 Apr 2003 10:06:02 -0000 Date: Mon, 14 Apr 2003 10:06:00 -0000 Message-ID: <20030414100602.4323.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: "Igor A. Goussarov" Subject: Re: c++/10332: Template classes are not instantiated correctly in presense of #pragma pack() Reply-To: "Igor A. Goussarov" X-SW-Source: 2003-04/txt/msg00602.txt.bz2 List-Id: The following reply was made to PR c++/10332; it has been noted by GNATS. From: "Igor A. Goussarov" To: Momchil Velikov Cc: ljrittle@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c++/10332: Template classes are not instantiated correctly in presense of #pragma pack() Date: Mon, 14 Apr 2003 14:02:26 +0400 Momchil Velikov wrote: >>>>>>"Igor" == Igor A Goussarov 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