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

            Bug ID: 119512
           Summary: -Wuninitialized does not diagnose use of uninitialized
                    member in constructor initialization list
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter0x44 at disroot dot org
  Target Milestone: ---

For the following testcase, that I reduced out of a beginner's snake game code:

https://gcc.godbolt.org/z/9PaE9nnG4
```
namespace std {
template <typename> class deque {};
}

class Food {
public:
  Food(std::deque<int>);
};

class Snake {
public:
  std::deque<int> body;
};

class Game {
  Game();
  Food food;
  Snake snake;
};

Game::Game() : food(snake.body) {}
```

clang emitted a warning about the uninitialized variable use, due to the order
of the class members:
<source>:21:21: warning: field 'snake' is uninitialized when used here
[-Wuninitialized]
   21 | Game::Game() : food(snake.body) {}
      |                     ^

but gcc does not emit any warning

Reply via email to