public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning
@ 2012-02-08  8:24 darko.veberic at ung dot si
  2012-02-08  9:04 ` [Bug c++/52167] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: darko.veberic at ung dot si @ 2012-02-08  8:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

             Bug #: 52167
           Summary: self-assignment should at least produce
                    use-of-uninitialized warning
    Classification: Unclassified
           Product: gcc
           Version: 4.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: darko.veberic@ung.si


the following code gets compiled without any warnings (even with -Wall
-Wextra):

std::string foo(foo);

and the resulting code segfaults (clang++ is also silent on this but the code
throws std::length_error).

i am aware that the example is ridiculous but it comes from a large real-life
project and is possibly a result of negligent copy-paste operations, so at
least issuing a warning would be nice.

full example:


#include <iostream>
#include <string>
using namespace std;

int
main()
{
  const string foo(foo);
  cout << foo << endl;
  return 0;
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/52167] self-assignment should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
@ 2012-02-08  9:04 ` redi at gcc dot gnu.org
  2012-02-08 10:20 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-08  9:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-02-08
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-08 09:03:41 UTC ---
You need -Winit-self, but it doesn't work for class types.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/52167] self-assignment should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
  2012-02-08  9:04 ` [Bug c++/52167] " redi at gcc dot gnu.org
@ 2012-02-08 10:20 ` rguenth at gcc dot gnu.org
  2012-02-08 14:01 ` manu at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-02-08 10:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/52167] self-assignment should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
  2012-02-08  9:04 ` [Bug c++/52167] " redi at gcc dot gnu.org
  2012-02-08 10:20 ` rguenth at gcc dot gnu.org
@ 2012-02-08 14:01 ` manu at gcc dot gnu.org
  2012-02-09  7:42 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu.org @ 2012-02-08 14:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-02-08 14:01:05 UTC ---
Clang++ 3.0 warns:

/tmp/webcompile/_14716_2.cc:8:20: warning: variable 'foo' is uninitialized when
used within its own initialization [-Wuninitialized]
  const string foo(foo);
               ~~~ ^~~
1 warning generated.

Clang improves a lot every 6 months, you should always check the latest version
(or SVN if possible).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/52167] self-assignment should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
                   ` (2 preceding siblings ...)
  2012-02-08 14:01 ` manu at gcc dot gnu.org
@ 2012-02-09  7:42 ` pinskia at gcc dot gnu.org
  2012-10-25  9:16 ` manu at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-09  7:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |48829, 48483

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-09 07:42:33 UTC ---
Related to PR 48829 and PR 48483.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/52167] self-assignment should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
                   ` (3 preceding siblings ...)
  2012-02-09  7:42 ` pinskia at gcc dot gnu.org
@ 2012-10-25  9:16 ` manu at gcc dot gnu.org
  2021-03-25 21:56 ` [Bug c++/52167] self-initialization " msebor at gcc dot gnu.org
  2021-03-25 22:25 ` [Bug tree-optimization/52167] " msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-25  9:16 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |miles at gnu dot org

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-10-25 09:15:35 UTC ---
*** Bug 53287 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/52167] self-initialization should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
                   ` (4 preceding siblings ...)
  2012-10-25  9:16 ` manu at gcc dot gnu.org
@ 2021-03-25 21:56 ` msebor at gcc dot gnu.org
  2021-03-25 22:25 ` [Bug tree-optimization/52167] " msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ 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=52167
Bug 52167 depends on bug 48483, which changed state.

Bug 48483 Summary: Construct from yourself w/o warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/52167] self-initialization should at least produce use-of-uninitialized warning
  2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
                   ` (5 preceding siblings ...)
  2021-03-25 21:56 ` [Bug c++/52167] self-initialization " msebor at gcc dot gnu.org
@ 2021-03-25 22:25 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-25 22:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
      Known to fail|                            |10.2.0, 4.1.0, 4.8.4,
                   |                            |4.9.4, 5.5.0, 6.4.0, 7.2.0,
                   |                            |8.3.0, 9.1.0
   Target Milestone|---                         |11.0
             Status|NEW                         |RESOLVED
          Component|c++                         |tree-optimization

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 11 (since g:b825a22890740f341eae566af27e18e528cd29a7) diagnoses passing an
uninitialized object by const reference by -Wmaybe-uninitialized:

$ g++ -S -Wall pr52167.C
pr52167.C: In function ‘int main()’:
pr52167.C:8:23: warning: ‘foo’ may be used uninitialized
[-Wmaybe-uninitialized]
    8 |   const string foo(foo);
      |                       ^
In file included from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/string:55,
                 from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/locale_classes.h:40,
                 from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ios_base.h:41,
                 from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/ios:42,
                 from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/ostream:38,
                 from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/iostream:39,
                 from pr52167.C:1:
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:448:7:
note: by argument 2 of type ‘const std::__cxx11::basic_string<char>&’ to
‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char;
_Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ declared here
  448 |       basic_string(const basic_string& __str)
      |       ^~~~~~~~~~~~
pr52167.C:8:16: note: ‘foo’ declared here
    8 |   const string foo(foo);
      |                ^~~

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-25 22:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-08  8:24 [Bug c++/52167] New: self-assignment should at least produce use-of-uninitialized warning darko.veberic at ung dot si
2012-02-08  9:04 ` [Bug c++/52167] " redi at gcc dot gnu.org
2012-02-08 10:20 ` rguenth at gcc dot gnu.org
2012-02-08 14:01 ` manu at gcc dot gnu.org
2012-02-09  7:42 ` pinskia at gcc dot gnu.org
2012-10-25  9:16 ` manu at gcc dot gnu.org
2021-03-25 21:56 ` [Bug c++/52167] self-initialization " msebor at gcc dot gnu.org
2021-03-25 22:25 ` [Bug tree-optimization/52167] " msebor 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).