Bug 15229 - Omits constructor calls for variables not used otherwise.
Summary: Omits constructor calls for variables not used otherwise.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-30 15:54 UTC by duz
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
The specs file from the compiler I've built here on Linux. (1.47 KB, text/plain)
2004-04-30 15:56 UTC, duz
Details
How I compiled the preprocessed source file plus compiler messages. (408 bytes, text/plain)
2004-04-30 15:57 UTC, duz
Details
The preprocessed source file. (166.95 KB, application/octet-stream)
2004-04-30 16:00 UTC, duz
Details
The resulting assembler source, which hopefully shows the problem. (8.06 KB, application/octet-stream)
2004-04-30 16:00 UTC, duz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description duz 2004-04-30 15:54:48 UTC
I have a variable of a class type. The side-effect of the constructor is
registering and ordering some stuff in a table. The variable is declared in
main. It is not used otherwise in main. Thus I want to achieve that the table's
contents is set up properly while main is running, i.e. after global constructor
runtime but before anything else interesting happens.

I tried to find a trivial test case, but trivial cases work fine. So here comes
the big one. Attached is preprocessed C++-file

    trader-main.ii

I compiled with the command

    g++-3.4 -v -S -O -fno-exceptions trader-main.ii

(The bug also happens when I replace -O by -g. Then I see when stepping
through the program, how the debugger omits the lines instantiating the
variables in question.)

The variables are of class "Lingo", constructor declared in line

    trader-main.ii:13863

The variable instantiations inside main is in lines

    trader-main.ii:46019 through 46021

You see clearly in the resulting assembly code, that these constructor
calls are missing at the beginning of main. There should be three
calls to "Lingo::Lingo" around line

    trader-main.s:310

The corresponding destructor calls are generated in lines

    trader-main.s:396 ff.

Thank you for your time.

Ups, where do I attach the files to this form?
I'll submit it now and try to add them later.
Comment 1 duz 2004-04-30 15:56:53 UTC
Created attachment 6198 [details]
The specs file from the compiler I've built here on Linux.
Comment 2 duz 2004-04-30 15:57:31 UTC
Created attachment 6199 [details]
How I compiled the preprocessed source file plus compiler messages.
Comment 3 duz 2004-04-30 16:00:10 UTC
Created attachment 6200 [details]
The preprocessed source file.
Comment 4 duz 2004-04-30 16:00:54 UTC
Created attachment 6201 [details]
The resulting assembler source, which hopefully shows the problem.
Comment 5 duz 2004-04-30 16:43:56 UTC
I just tried it on solaris-8 for sparc, with the compiler prebuilt from
sunfreeware.com:

$ /usr/local/bin/g++ -v -help 
Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.8/3.4.0/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as
--with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.4.0
$ 

Same problem.
Comment 6 Andrew Pinski 2004-04-30 17:22:00 UTC
Invalid, this code is equivent to this simplifed case:
struct Lingo
{
  Lingo ();
};
struct ALingo : Lingo
{
  ALingo();
};
int main()
{
  ALingo a;
  Lingo b(a); // <-- calls the copy constrctor
}

Since there is no user defined copy constructor, the compiler creates one for you (by the rules of C++).
So this is invalid, to solve this you need to define a copy constructor.