[llvm-bugs] [Bug 29080] New: Differences of lifetime of temporary objects during list-initialization with g++, MSVS and icpc
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Aug 21 05:59:25 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=29080
Bug ID: 29080
Summary: Differences of lifetime of temporary objects during
list-initialization with g++,MSVS and icpc
Product: clang
Version: 3.8
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: noone at turm-lahnstein.de
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
Following this stackoverflow discussion
http://stackoverflow.com/questions/39025342/lifetime-of-temporary-objects-during-list-initialization
The behaviour of clang differs from the behaviour of other compilers for this
code:
#include <iostream>
#include <vector>
struct ID{
static int cnt;
// the number of living object of class ID at the moment of creation:
int id;
ID():id(++cnt){}
~ID(){
cnt--;
}
};
int ID::cnt=0;
int main(){
int arr[]{ID().id, ID().id};
std::cout<<" Array: "<<arr[0]<<", "<<arr[1]<<"\n";
}
The clang compiled program prints out "1, 2", but programs produced by other
compilers give "1, 1".
Actually, I don't know what the right behaviour should be, but because other
compilers seem to agree, I report the bug here.
--
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/20160821/d475a494/attachment.html>
More information about the llvm-bugs
mailing list