public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/113987] New: Binding a reference to an uninitialized data member should not cause -Wuninitialized
@ 2024-02-19  5:17 i at maskray dot me
  2024-02-19  5:18 ` [Bug middle-end/113987] " i at maskray dot me
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: i at maskray dot me @ 2024-02-19  5:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113987
           Summary: Binding a reference to an uninitialized data member
                    should not cause -Wuninitialized
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i at maskray dot me
  Target Milestone: ---

https://godbolt.org/z/G7ndsTv5c (from
https://github.com/llvm/llvm-project/pull/81179#issuecomment-1937082113)

struct t1 {
    t1(int);
};
struct t2 {
    t2(int&, int = 0);
};
struct t3 {
    t3(int&);
};
struct t4 {};
void f1(int&);
struct t {
    t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
    t1 v1;
    t2 v2;
    t3 v3;
    t4 v4;
    t1 v5;
    int i;
    int j;
};
int main() { t v1; }

GCC output
```
<source>: In constructor 't::t()':
<source>:13:14: warning: member 't::i' is used uninitialized [-Wuninitialized]
   13 |     t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
      |              ^
<source>:13:21: warning: member 't::i' is used uninitialized [-Wuninitialized]
   13 |     t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
      |                     ^
<source>:13:28: warning: member 't::i' is used uninitialized [-Wuninitialized]
   13 |     t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
      |                            ^
<source>: In constructor 't::t()':
<source>:13:11: warning: '*this.t::i' is used uninitialized [-Wuninitialized]
   13 |     t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
      |           ^~~~~
```

Clang output
```
<source>:13:14: warning: field 'i' is uninitialized when used here
[-Wuninitialized]
   13 |     t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
      |              ^
<source>:13:54: warning: field 'i' is uninitialized when used here
[-Wuninitialized]
   13 |     t() : v1(i), v2(i), v3(i), v4((f1(i), t4())), v5(i) {}
      |                                                      ^
2 warnings generated.
```

Clang suppresses diagnostics when binding a reference (t2, t3) to an
uninitialized data member.


Smaller example:

  struct D {
    int a;
    int &b;
    int &c = a;
    D() : b(a) {}             // no warning ?!
    D(int x) : b(a), a(x) {}  // warning
  };

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

end of thread, other threads:[~2024-02-29 18:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-19  5:17 [Bug middle-end/113987] New: Binding a reference to an uninitialized data member should not cause -Wuninitialized i at maskray dot me
2024-02-19  5:18 ` [Bug middle-end/113987] " i at maskray dot me
2024-02-19  5:26 ` [Bug c++/113987] [12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-02-19  5:26 ` pinskia at gcc dot gnu.org
2024-02-19  5:32 ` pinskia at gcc dot gnu.org
2024-02-19  7:26 ` jakub at gcc dot gnu.org
2024-02-19  8:18 ` rguenth at gcc dot gnu.org
2024-02-20 15:41 ` mpolacek at gcc dot gnu.org
2024-02-20 20:54 ` mpolacek at gcc dot gnu.org
2024-02-21 13:53 ` mpolacek at gcc dot gnu.org
2024-02-29 17:41 ` cvs-commit at gcc dot gnu.org
2024-02-29 18:05 ` [Bug c++/113987] [12/13 " mpolacek 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).