public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53753] New: stack based constructor is not called for Class1 Object1()
@ 2012-06-23 8:21 kiran.puttur at gmail dot com
2012-06-23 8:55 ` [Bug c++/53753] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kiran.puttur at gmail dot com @ 2012-06-23 8:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53753
Bug #: 53753
Summary: stack based constructor is not called for Class1
Object1()
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kiran.puttur@gmail.com
I have gcc version 4.7.0 (Ubuntu/Linaro 4.7.0-7ubuntu3) I have following
program
#include<iostream>
class Myclass
{
public:
Myclass() {
std::cout<<"Value of mInt : "<< mInt << " value mStr : " << mStr
<<std::endl;
std::cout<<"test complete" << std::endl;
}
protected:
int mInt;
std::string mStr;
};
int main(void)
{
Myclass instance1();
return 0;
}
if I compile the program with following options
#g++ -W -Wall -Wextra -pedantic -std=c++0x -c inclass-member-initialize.cpp -o
inclass-member-initialize.o
#g++ inclass-member-initialize.o -o output
and If I run the output program
#output
It doesn't show constructor initialization statement at all
But if i modify the line as
Myclass instance1 = Myclass();
Then the constructor is getting called, and I can see test messages.
Even constructor on heap also shows up without any issues such as
Myclass *instance1 = new Myclass();
works just fine,
Just the intialization like Myclass instance1() is currently having issues
Is this expected ?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53753] stack based constructor is not called for Class1 Object1()
2012-06-23 8:21 [Bug c++/53753] New: stack based constructor is not called for Class1 Object1() kiran.puttur at gmail dot com
@ 2012-06-23 8:55 ` pinskia at gcc dot gnu.org
2012-06-23 9:59 ` daniel.kruegler at googlemail dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-06-23 8:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53753
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-06-23 08:55:40 UTC ---
> Myclass instance1();
I think this is really a function declaration name instance1 returning Myclass
and not a variable declaration.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53753] stack based constructor is not called for Class1 Object1()
2012-06-23 8:21 [Bug c++/53753] New: stack based constructor is not called for Class1 Object1() kiran.puttur at gmail dot com
2012-06-23 8:55 ` [Bug c++/53753] " pinskia at gcc dot gnu.org
@ 2012-06-23 9:59 ` daniel.kruegler at googlemail dot com
2012-06-23 10:14 ` kiran.puttur at gmail dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-06-23 9:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53753
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler at
| |googlemail dot com
--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-06-23 09:58:58 UTC ---
I agree with Andrew, there is no object defined in the code, so the behaviour
is expected.
Since you are using C++11 mode you can use a pair of braces here:
Myclass instance1{};
This will be a guaranteed variable definition and allows uniform initialization
even for built-in types.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53753] stack based constructor is not called for Class1 Object1()
2012-06-23 8:21 [Bug c++/53753] New: stack based constructor is not called for Class1 Object1() kiran.puttur at gmail dot com
2012-06-23 8:55 ` [Bug c++/53753] " pinskia at gcc dot gnu.org
2012-06-23 9:59 ` daniel.kruegler at googlemail dot com
@ 2012-06-23 10:14 ` kiran.puttur at gmail dot com
2012-06-23 10:15 ` kiran.puttur at gmail dot com
2012-06-23 11:58 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: kiran.puttur at gmail dot com @ 2012-06-23 10:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53753
--- Comment #3 from Kiran Puttur <kiran.puttur at gmail dot com> 2012-06-23 10:14:38 UTC ---
Thanks Andrew, Daniel,
If I use the braces {} then I can see my testing strings printed in the program
output
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53753] stack based constructor is not called for Class1 Object1()
2012-06-23 8:21 [Bug c++/53753] New: stack based constructor is not called for Class1 Object1() kiran.puttur at gmail dot com
` (2 preceding siblings ...)
2012-06-23 10:14 ` kiran.puttur at gmail dot com
@ 2012-06-23 10:15 ` kiran.puttur at gmail dot com
2012-06-23 11:58 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: kiran.puttur at gmail dot com @ 2012-06-23 10:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53753
--- Comment #4 from Kiran Puttur <kiran.puttur at gmail dot com> 2012-06-23 10:15:22 UTC ---
Thanks Andrew, Daniel,
If I use the braces {} then I can see my testing strings printed in the program
output
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53753] stack based constructor is not called for Class1 Object1()
2012-06-23 8:21 [Bug c++/53753] New: stack based constructor is not called for Class1 Object1() kiran.puttur at gmail dot com
` (3 preceding siblings ...)
2012-06-23 10:15 ` kiran.puttur at gmail dot com
@ 2012-06-23 11:58 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-06-23 11:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53753
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-06-23 11:57:53 UTC ---
see http://en.wikipedia.org/wiki/Most_vexing_parse
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-06-23 11:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-23 8:21 [Bug c++/53753] New: stack based constructor is not called for Class1 Object1() kiran.puttur at gmail dot com
2012-06-23 8:55 ` [Bug c++/53753] " pinskia at gcc dot gnu.org
2012-06-23 9:59 ` daniel.kruegler at googlemail dot com
2012-06-23 10:14 ` kiran.puttur at gmail dot com
2012-06-23 10:15 ` kiran.puttur at gmail dot com
2012-06-23 11:58 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).