<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59754>59754</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Default constructor of `std::chrono::duration` does not initialize member variable
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sxlijin
      </td>
    </tr>
</table>

<pre>
    Hi there- first time contributor, seeking suggestions for next steps and the communication channels I should use to pursue such.

I recently made the (painful) discovery that the default constructor of `std::chrono::duration` does not initialize its tick counter: [godbolt demo][godbolt]. (In my specific case, the bug was that I was using a default-initialized `duration` to sum up other `duration` instances, and we were observing that the sum was effectively random.)

Drilling down into my experience here:

* this issue exists in both [`libc++`][libcxx] and [`libstdc++`][libstdc++]
* the issue _arguably_ exists in the standard: [\[time.duration.cons\]][time.duration.cons] does not actually specify the behavior of the default constructor, even though [\[time.duration.general\]][time.duration.general] specifies that a default constructor should exist
  * there is an exposition-only suggestion in [\[time.duration.general\]][time.duration.general] that suggests using default initialization for the tick counter, so the standard does not specify the buggy behavior
* as a C++ user, I would expect `clang-tidy` to detect this via `cppcoreguidelines-init-variables`; I realize this is a can of worms, since the physical location of the code is inside the STL and would have to be mapped to an instantiation of a relevant STL type

So far I've [received one vote for "the problem is the standard"][discord].

[godbolt]: https://godbolt.org/z/sxYPqMbYr
[libcxx]: https://github.com/llvm/llvm-project/blob/1ae7d83803e45f6053ec6a606f259653846926b8/libcxx/include/__chrono/duration.h#L239
[libstdc++]: https://github.com/gcc-mirror/gcc/blob/603da201681ad06342055e8c12a656f5289e52a8/libstdc%2B%2B-v3/include/bits/chrono.h#L696
[time.duration.cons]: https://eel.is/c++draft/time.duration#cons
[time.duration.general]: https://eel.is/c++draft/time.duration#general
[discord]: https://discordapp.com/channels/636084430946959380/636732894974312448/1058461265837690921
</pre>
<img width="1px" height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