<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Storage duration inference via `auto&`: Discrepancy in behavior between g++-5.4 and clang++-6.0"
   href="https://bugs.llvm.org/show_bug.cgi?id=39202">39202</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Storage duration inference via `auto&`: Discrepancy in behavior between g++-5.4 and clang++-6.0
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++14
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eric.cousineau@tri.global
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20972" name="attach_20972" title="output.txt">attachment 20972</a> <a href="attachment.cgi?id=20972&action=edit" title="output.txt">[details]</a></span>
output.txt

My apologies if this is not the right project to file (here vs. GCC), if these
versions are too old, or if there are too many things in one report; however, I
found some discrepancies between clang-6.0 and gcc-5.4.

I have a file, `output.txt`, which provides compiler versions and numbered
cases / results for the compilers. C++14 is used for both.

In each case, there is a defined variable, `top_doc`, and a local alias
variable, `doc`. Each case will vary the storage duration for both the defined
variable (and sometimes the local alias), and effectively checks the storage
duration by how the compiler treats the relevant lambda capture.

Observations and guesses from these results:

[ Storage duration defined by scope ]
- Case 0 (clang fails): clang propagates storage duration (static) via `auto&`,
while gcc does not; clang raises `-Wunused-lambda-capture`
- Case 1 (gcc fails): same observation as Case 0; gcc says capture is
insufficient
- Case 2 (both work): automatic storage works (of course)

[ Storage duration defined by specifier, `constexpr` ]
- Case 3 (clang fails): same as Case 0, clang propagates storage duration via
`auto&`; same result as Case 0
- Case 4 (gcc fails): same as Case 1
- Case 5 (both work): make storage of intermediate variable explicit,
`constexpr auto&`

Overall, it seems that `clang` is propagating the storage duration (either via
scope or `constexpr`) via `auto&`, which conditionally affects the storage
duration of `doc`; `gcc`, however, does not seem to do this.

Can I ask which one might be incorrect?

P.S. The following script was used to produce the output:
<a href="https://github.com/EricCousineau-TRI/repro/blob/02530c9/bug/clang_unused_lambda_capture/repro.sh">https://github.com/EricCousineau-TRI/repro/blob/02530c9/bug/clang_unused_lambda_capture/repro.sh</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>