[llvm-bugs] [Bug 39202] New: Storage duration inference via `auto&`: Discrepancy in behavior between g++-5.4 and clang++-6.0
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Oct 6 12:00:46 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=39202
Bug ID: 39202
Summary: Storage duration inference via `auto&`: Discrepancy in
behavior between g++-5.4 and clang++-6.0
Product: clang
Version: 6.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: eric.cousineau at tri.global
CC: llvm-bugs at lists.llvm.org
Created attachment 20972
--> https://bugs.llvm.org/attachment.cgi?id=20972&action=edit
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:
https://github.com/EricCousineau-TRI/repro/blob/02530c9/bug/clang_unused_lambda_capture/repro.sh
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181006/d7161a60/attachment.html>
More information about the llvm-bugs
mailing list