Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

init-capture of initializer_list fails to extend lifetime #38309

Closed Quuxplusone closed 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR39336
Status RESOLVED FIXED
Importance P normal
Reported by hstong@ca.ibm.com
Reported on 2018-10-17 20:04:53 -0700
Last modified on 2018-10-19 12:16:31 -0700
Version trunk
Hardware All All
CC llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also PR24164
Similar to PR 24164, but expressed using an initializer_list captured by value.
Clang does not extend the lifetime of the temporary array to the lifetime of
the init-capture. GCC does extend the lifetime.

### SOURCE (<stdin>):
#include <initializer_list>
extern "C" int printf(const char *, ...);

struct A {
  A() = default;
  A(const A &) = default;
  ~A() { printf("%s\n", __PRETTY_FUNCTION__); }
};

int main(void) {
  A a;
  [list = { a }] { printf("Hi.\n"); }();
}

### COMPILER INVOCATION:
clang++ -xc++ -std=c++14 -o prog -

### RUN INVOCATION:
./prog

### ACTUAL RUN OUTPUT:
A::~A()
Hi.
A::~A()

### EXPECTED RUN OUTPUT:
A::~A()
A::~A()
Hi.

### COMPILER VERSION INFO (clang++ -v):
clang version 8.0.0 (https://github.com/llvm-mirror/clang.git
bcda707b20ee8c1ad0ce4e9503c761c85e6ce624) (https://github.com/llvm-
mirror/llvm.git 4998e62d5745cca132cf92cec718be0746e70bcf)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
Quuxplusone commented 6 years ago
Fixed in r344801.

> ### EXPECTED RUN OUTPUT:
> A::~A()
> A::~A()
> Hi.

You meant

### EXPECTED RUN OUTPUT:
Hi.
A::~A()
A::~A()

Right? =)
Quuxplusone commented 6 years ago
(In reply to Richard Smith from comment #1)
> You meant
>
> ### EXPECTED RUN OUTPUT:
> Hi.
> A::~A()
> A::~A()
>
> Right? =)
Yes. A case where doing copy/paste more would have helped...