public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48483] New: Construct from yourself w/o warning
@ 2011-04-06 17:38 lisp2d at lisp2d dot net
2011-04-06 19:20 ` [Bug c++/48483] " d.g.gorbachev at gmail dot com
` (22 more replies)
0 siblings, 23 replies; 24+ messages in thread
From: lisp2d at lisp2d dot net @ 2011-04-06 17:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Summary: Construct from yourself w/o warning
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: lisp2d@lisp2d.net
Simple slip in my program bring to waste the time.
Writing the constructor with arguments of new object bring to crash.
No warnings and deep stillness.
The example to crash:
#include<iostream>
class B{
public:
int x;
};
class A{
public:
B& b;
A(B&x):b(x){}
};
int main(void){
A a(a.b);
std::clog<<"a.b.x="<<a.b.x<<std::endl;}
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
@ 2011-04-06 19:20 ` d.g.gorbachev at gmail dot com
2011-04-06 21:15 ` lisp2d at lisp2d dot net
` (21 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-04-06 19:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #1 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 2011-04-06 19:20:02 UTC ---
> No warnings and deep stillness.
$ g++ -O -Wuninitialized pr48483.cc
pr48483.cc: In function 'int main()':
pr48483.cc:13:30: warning: 'a.A::b' is used uninitialized in this function
From
<http://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/Warning-Options.html#index-Wuninitialized-309>:
Because these warnings depend on optimization, the exact variables
or elements for which there are warnings will depend on the precise
optimization options and version of GCC used.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
2011-04-06 19:20 ` [Bug c++/48483] " d.g.gorbachev at gmail dot com
@ 2011-04-06 21:15 ` lisp2d at lisp2d dot net
2011-04-06 22:38 ` d.g.gorbachev at gmail dot com
` (20 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: lisp2d at lisp2d dot net @ 2011-04-06 21:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #2 from Lisp2D <lisp2d at lisp2d dot net> 2011-04-06 21:15:42 UTC ---
Try the next example, more close to my code:
#include<iostream>
class A{
public:
int a;
A(int x):a(x){}
int TheInt(){return a;}
};
void Func(A&a){
std::clog<<"a.a="<<a.a<<std::endl;}
int main(void){
A a(a.TheInt());
Func(a);}
g++ -O -Winit-self -obug -Wall -Wextra bug.cpp
no warning
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
2011-04-06 19:20 ` [Bug c++/48483] " d.g.gorbachev at gmail dot com
2011-04-06 21:15 ` lisp2d at lisp2d dot net
@ 2011-04-06 22:38 ` d.g.gorbachev at gmail dot com
2011-04-06 22:58 ` d.g.gorbachev at gmail dot com
` (19 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-04-06 22:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Dmitry Gorbachev <d.g.gorbachev at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |d.g.gorbachev at gmail dot
| |com
--- Comment #3 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 2011-04-06 22:38:20 UTC ---
Simpler testcase:
int main(void)
{
struct S { int a; } s;
return s.a;
}
It's a regression (latest working version is 4.4). I think there is a duplicate
PR somewhere.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (2 preceding siblings ...)
2011-04-06 22:38 ` d.g.gorbachev at gmail dot com
@ 2011-04-06 22:58 ` d.g.gorbachev at gmail dot com
2011-04-06 23:50 ` redi at gcc dot gnu.org
` (18 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-04-06 22:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Dmitry Gorbachev <d.g.gorbachev at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #4 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 2011-04-06 22:57:57 UTC ---
It's similar to bug 42905.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (3 preceding siblings ...)
2011-04-06 22:58 ` d.g.gorbachev at gmail dot com
@ 2011-04-06 23:50 ` redi at gcc dot gnu.org
2011-04-07 1:39 ` d.g.gorbachev at gmail dot com
` (17 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-06 23:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-06 23:50:38 UTC ---
and PR 18016 but I don't think my patch will catch this
there's a limit to how much silliness the compiler can catch, at some point you
have to just not write silly code ;)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (4 preceding siblings ...)
2011-04-06 23:50 ` redi at gcc dot gnu.org
@ 2011-04-07 1:39 ` d.g.gorbachev at gmail dot com
2011-04-07 4:33 ` lisp2d at lisp2d dot net
` (16 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-04-07 1:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #6 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 2011-04-07 01:38:53 UTC ---
> there's a limit to how much silliness the compiler can catch,
> at some point you have to just not write silly code ;)
Yes, these reduced fragments look embarrassing.
Of course, compiler is not a tool for static checking. So, it's simply a small
enhancement request, rather then a complain about bugs in GCC. GCC devs should
concentrate efforts on real bugs. Still, it would be good if somebody will fix
this thing.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (5 preceding siblings ...)
2011-04-07 1:39 ` d.g.gorbachev at gmail dot com
@ 2011-04-07 4:33 ` lisp2d at lisp2d dot net
2011-04-07 6:20 ` d.g.gorbachev at gmail dot com
` (15 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: lisp2d at lisp2d dot net @ 2011-04-07 4:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #7 from Lisp2D <lisp2d at lisp2d dot net> 2011-04-07 04:33:52 UTC ---
The example
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483#c2
shows a compiler bug.
TYPE VARIABLE [ARGUMENT-TO-CONSTRUCT]
The compiler must doing like this:
1. Compile ARGUMENT-TO-CONSTRUCT
2. Checking of TYPE
3. VARIABLE declaration
The BIG mistake is declaration of VARIABLE from wrong position.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (6 preceding siblings ...)
2011-04-07 4:33 ` lisp2d at lisp2d dot net
@ 2011-04-07 6:20 ` d.g.gorbachev at gmail dot com
2011-04-07 9:42 ` redi at gcc dot gnu.org
` (14 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-04-07 6:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #8 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 2011-04-07 06:20:24 UTC ---
There is a call to a non-static member function of the object before
initialization by a constructor. That's undefined behavior. Not a compiler bug.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (7 preceding siblings ...)
2011-04-07 6:20 ` d.g.gorbachev at gmail dot com
@ 2011-04-07 9:42 ` redi at gcc dot gnu.org
2011-04-07 13:19 ` lisp2d at lisp2d dot net
` (13 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-07 9:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 09:41:55 UTC ---
(In reply to comment #7)
> The example
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483#c2
>
> shows a compiler bug.
No it doesn't.
> TYPE VARIABLE [ARGUMENT-TO-CONSTRUCT]
>
> The compiler must doing like this:
> 1. Compile ARGUMENT-TO-CONSTRUCT
> 2. Checking of TYPE
> 3. VARIABLE declaration
No, the variable is in scope after its identifier, so it can be used in the
initializer expression, e.g.
int i = sizeof(i); // ok
int i = i+1; // not ok
> The BIG mistake is declaration of VARIABLE from wrong position.
No, C++ does not work the way you think it does.
It's not a bug. It would be nice to get a warning, but it's not easy to do
that.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (8 preceding siblings ...)
2011-04-07 9:42 ` redi at gcc dot gnu.org
@ 2011-04-07 13:19 ` lisp2d at lisp2d dot net
2011-04-07 13:26 ` redi at gcc dot gnu.org
` (12 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: lisp2d at lisp2d dot net @ 2011-04-07 13:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #10 from Lisp2D <lisp2d at lisp2d dot net> 2011-04-07 13:19:16 UTC ---
(In reply to comment #9)
> No, the variable is in scope after its identifier, so it can be used in the
> initializer expression, e.g.
>
> int i = sizeof(i); // ok
> int i = i+1; // not ok
My opinion is that C habit rules here.
In C
int i=i+1; -> int i; i=i+1;
without constructors, objects e.t.c.
This example will bring just a warning.
In C++
Class i(i.Method()); eval i.Method() -> construct with Class::Class(result)
another order of calculation. (see comment 2) Must be an error.
The answer of question gives the C++ standard. Show me this document.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (9 preceding siblings ...)
2011-04-07 13:19 ` lisp2d at lisp2d dot net
@ 2011-04-07 13:26 ` redi at gcc dot gnu.org
2011-04-07 13:29 ` redi at gcc dot gnu.org
` (11 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-07 13:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 13:26:16 UTC ---
(In reply to comment #10)
> The answer of question gives the C++ standard. Show me this document.
3.3.1 Point of declaration [basic.scope.decl]
1 The point of declaration for a name is immediately after its complete
declarator (clause 8) and before its initializer (if any), except as noted
below. [Example:
int x = 12;
{ int x = x; }
Here the second x is initialized with its own (indeterminate) value. ]
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (10 preceding siblings ...)
2011-04-07 13:26 ` redi at gcc dot gnu.org
@ 2011-04-07 13:29 ` redi at gcc dot gnu.org
2011-04-07 13:38 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-07 13:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 13:29:43 UTC ---
For the example in comment 2 G++, EDG and Clang++ all accept it without
warning.
MSVC rejects it, but is wrong to do so.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (11 preceding siblings ...)
2011-04-07 13:29 ` redi at gcc dot gnu.org
@ 2011-04-07 13:38 ` redi at gcc dot gnu.org
2011-04-07 13:39 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-07 13:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 13:38:11 UTC ---
(In reply to comment #10)
> (In reply to comment #9)
>
> > No, the variable is in scope after its identifier, so it can be used in the
> > initializer expression, e.g.
> >
> > int i = sizeof(i); // ok
> > int i = i+1; // not ok
>
> My opinion is that C habit rules here.
>
> In C
>
> int i=i+1; -> int i; i=i+1;
In C++ this can be written:
int i(i+1);
The initialization rules for C++ do
> without constructors, objects e.t.c.
> This example will bring just a warning.
>
> In C++
>
> Class i(i.Method()); eval i.Method() -> construct with Class::Class(result)
Note that this is similar to:
Class i = i.Method();
For the purposes of your complaint it's not relevant that it's a class with a
constructor.
Obviously "i.Method()" has to be evaluated first at runtime, but that doesn't
make it a compile-time error. "i" is in scope as soon a "Class i" has been
parsed, so the expression "i.Method()" in the initializer can be compiled.
> another order of calculation. (see comment 2) Must be an error.
No. The behaviour at runtime is undefined, but it is not an error at compile
time - the syntax is valid, but the result is undefined.
I understand what you're saying, but you're wrong. C++ doesn't work how you
think it works.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (12 preceding siblings ...)
2011-04-07 13:38 ` redi at gcc dot gnu.org
@ 2011-04-07 13:39 ` redi at gcc dot gnu.org
2011-04-07 13:58 ` lisp2d at lisp2d dot net
` (8 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-07 13:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 13:39:45 UTC ---
(In reply to comment #13)
> (In reply to comment #10)
> > (In reply to comment #9)
> >
> > > No, the variable is in scope after its identifier, so it can be used in the
> > > initializer expression, e.g.
> > >
> > > int i = sizeof(i); // ok
> > > int i = i+1; // not ok
> >
> > My opinion is that C habit rules here.
> >
> > In C
> >
> > int i=i+1; -> int i; i=i+1;
>
> In C++ this can be written:
>
> int i(i+1);
>
> The initialization rules for C++ do
... not care if the type is a class or not, the variable name is still in scope
before the initializer is parsed.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (13 preceding siblings ...)
2011-04-07 13:39 ` redi at gcc dot gnu.org
@ 2011-04-07 13:58 ` lisp2d at lisp2d dot net
2011-04-07 14:01 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: lisp2d at lisp2d dot net @ 2011-04-07 13:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #15 from Lisp2D <lisp2d at lisp2d dot net> 2011-04-07 13:58:38 UTC ---
(In reply to comment #12)
> For the example in comment 2 G++, EDG and Clang++ all accept it without
> warning.
> MSVC rejects it, but is wrong to do so.
The answer is good. Let's talk about warnings.
I think that processing option -Winit-self must to be rewritten.
Just create SymbolVariableProcessingInConstructor and checking of all symbols
in line.
This will free the brain.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (14 preceding siblings ...)
2011-04-07 13:58 ` lisp2d at lisp2d dot net
@ 2011-04-07 14:01 ` redi at gcc dot gnu.org
2012-02-09 11:35 ` manu at gcc dot gnu.org
` (6 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2011-04-07 14:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011.04.07 14:01:09
Ever Confirmed|0 |1
Severity|normal |enhancement
--- Comment #16 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-04-07 14:01:09 UTC ---
Confirming as an enhancement request for a warning from:
struct A {
A(int);
int i;
};
A a(a.i);
-Winit-self doesn't work properly for C++, this is a known issue.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (15 preceding siblings ...)
2011-04-07 14:01 ` redi at gcc dot gnu.org
@ 2012-02-09 11:35 ` manu at gcc dot gnu.org
2012-02-09 16:59 ` lisp2d at lisp2d dot net
` (5 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: manu at gcc dot gnu.org @ 2012-02-09 11:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #17 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-02-09 11:35:27 UTC ---
Clang++ 3.0 warns with -Wuninitialized
/tmp/webcompile/_15338_0.cc:7:5: warning: variable 'a' is uninitialized when
used within its own initialization [-Wuninitialized]
A a(a.i);
~ ^
1 warning generated.
but it doesn't warn for the testcase in comment #2.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (16 preceding siblings ...)
2012-02-09 11:35 ` manu at gcc dot gnu.org
@ 2012-02-09 16:59 ` lisp2d at lisp2d dot net
2012-02-09 17:04 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: lisp2d at lisp2d dot net @ 2012-02-09 16:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #18 from Lisp2D <lisp2d at lisp2d dot net> 2012-02-09 16:59:19 UTC ---
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483#c2
shows that function calling of object before constructor is bad idea and must
be strongly forbidden.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (17 preceding siblings ...)
2012-02-09 16:59 ` lisp2d at lisp2d dot net
@ 2012-02-09 17:04 ` redi at gcc dot gnu.org
2012-02-09 21:38 ` manu at gcc dot gnu.org
` (3 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-09 17:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #19 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-09 17:04:06 UTC ---
Everyone knows it's a bad idea, and everyone agrees there should be a warning.
Stop going on about it.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (18 preceding siblings ...)
2012-02-09 17:04 ` redi at gcc dot gnu.org
@ 2012-02-09 21:38 ` manu at gcc dot gnu.org
2014-11-23 14:58 ` paolo.carlini at oracle dot com
` (2 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: manu at gcc dot gnu.org @ 2012-02-09 21:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #20 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-02-09 21:37:38 UTC ---
(In reply to comment #18)
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483#c2
> shows that function calling of object before constructor is bad idea and must
> be strongly forbidden.
Lisp2D, I think you could start with the testcase in comment 16, and try to
figure out what would be needed to detect this case, as a firt step. All the
code you need to look is in the C++ FE. Use gdb and follow the code. See also
http://gcc.gnu.org/contribute.html and http://gcc.gnu.org/wiki/GettingStarted
But if you expect that someone else is going to fix this for you, I think you
may wait a long time. There are many bugs to fix.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug c++/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (19 preceding siblings ...)
2012-02-09 21:38 ` manu at gcc dot gnu.org
@ 2014-11-23 14:58 ` paolo.carlini at oracle dot com
2021-03-25 21:56 ` [Bug tree-optimization/48483] " msebor at gcc dot gnu.org
2021-03-25 22:09 ` cvs-commit at gcc dot gnu.org
22 siblings, 0 replies; 24+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-11-23 14:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lundberj at gmail dot com
--- Comment #21 from Paolo Carlini <paolo.carlini at oracle dot com> ---
*** Bug 57758 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug tree-optimization/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (20 preceding siblings ...)
2014-11-23 14:58 ` paolo.carlini at oracle dot com
@ 2021-03-25 21:56 ` msebor at gcc dot gnu.org
2021-03-25 22:09 ` cvs-commit at gcc dot gnu.org
22 siblings, 0 replies; 24+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-25 21:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |10.2.0, 11.0, 5.1.0
Status|NEW |RESOLVED
Component|c++ |tree-optimization
Resolution|--- |FIXED
CC| |msebor at gcc dot gnu.org
--- Comment #22 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC diagnoses the test case in comment #0 at -O0 (one warning) as well as above
(two warnings) since r209443:
pr48483.C: In function ‘int main()’:
pr48483.C:12:22: warning: ‘a.A::b’ is used uninitialized [-Wuninitialized]
12 | A a(a.b);
| ^
pr48483.C:12:17: note: ‘a’ declared here
12 | A a(a.b);
| ^
With -O1 and higher it also diagnoses the test case in comment #2:
In member function ‘int A::TheInt()’,
inlined from ‘int main()’ at pr48483-c2.C:11:16:
pr48483-c2.C:6:33: warning: ‘a.A::a’ is used uninitialized [-Wuninitialized]
6 | int TheInt(){return a;}
| ^
pr48483-c2.C: In function ‘int main()’:
pr48483-c2.C:11:17: note: ‘a’ declared here
11 | A a(a.TheInt());
| ^
At -O0 and above it also diagnoses the test case in comment #3 (also since
r209443)
pr48483-c3.C:5:12: warning: ‘s.main()::S::a’ is used uninitialized
[-Wuninitialized]
5 | return s.a;
| ^
pr48483-c3.C:4:23: note: ‘s’ declared here
4 | struct S { int a; } s;
| ^
The test case in comment #16 isn't diagnosed but that one is sufficiently
different that I think it should be tracked separately (if it isn't yet; I
suspect there probably is a duplicate somewhere but if not I'll add one).
With that, let me add the passing test cases and resolve this as fixed.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug tree-optimization/48483] Construct from yourself w/o warning
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
` (21 preceding siblings ...)
2021-03-25 21:56 ` [Bug tree-optimization/48483] " msebor at gcc dot gnu.org
@ 2021-03-25 22:09 ` cvs-commit at gcc dot gnu.org
22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-25 22:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483
--- Comment #23 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:26e80a496853b21da1886779d97ff613ccb64f9b
commit r11-7840-g26e80a496853b21da1886779d97ff613ccb64f9b
Author: Martin Sebor <msebor@redhat.com>
Date: Thu Mar 25 16:08:00 2021 -0600
PR tree-optimization/48483 - Construct from yourself w/o warning
gcc/testsuite/ChangeLog:
PR tree-optimization/48483
* g++.dg/warn/uninit-pr48483.C: New test.
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2021-03-25 22:09 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-06 17:38 [Bug c++/48483] New: Construct from yourself w/o warning lisp2d at lisp2d dot net
2011-04-06 19:20 ` [Bug c++/48483] " d.g.gorbachev at gmail dot com
2011-04-06 21:15 ` lisp2d at lisp2d dot net
2011-04-06 22:38 ` d.g.gorbachev at gmail dot com
2011-04-06 22:58 ` d.g.gorbachev at gmail dot com
2011-04-06 23:50 ` redi at gcc dot gnu.org
2011-04-07 1:39 ` d.g.gorbachev at gmail dot com
2011-04-07 4:33 ` lisp2d at lisp2d dot net
2011-04-07 6:20 ` d.g.gorbachev at gmail dot com
2011-04-07 9:42 ` redi at gcc dot gnu.org
2011-04-07 13:19 ` lisp2d at lisp2d dot net
2011-04-07 13:26 ` redi at gcc dot gnu.org
2011-04-07 13:29 ` redi at gcc dot gnu.org
2011-04-07 13:38 ` redi at gcc dot gnu.org
2011-04-07 13:39 ` redi at gcc dot gnu.org
2011-04-07 13:58 ` lisp2d at lisp2d dot net
2011-04-07 14:01 ` redi at gcc dot gnu.org
2012-02-09 11:35 ` manu at gcc dot gnu.org
2012-02-09 16:59 ` lisp2d at lisp2d dot net
2012-02-09 17:04 ` redi at gcc dot gnu.org
2012-02-09 21:38 ` manu at gcc dot gnu.org
2014-11-23 14:58 ` paolo.carlini at oracle dot com
2021-03-25 21:56 ` [Bug tree-optimization/48483] " msebor at gcc dot gnu.org
2021-03-25 22:09 ` cvs-commit 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).