[LLVMbugs] [Bug 20844] New: Brace-init of non-const references produces code that crashes
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Sep 4 05:54:49 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20844
Bug ID: 20844
Summary: Brace-init of non-const references produces code that
crashes
Product: clang
Version: 3.4
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: petar335335 at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 12983
--> http://llvm.org/bugs/attachment.cgi?id=12983&action=edit
the program used to reproduce the bug
The attached program produces the following and crashes on Ubuntu LTS 14.04
AMD64:
-----------------------------------------------------------------
random value
65
Segmentation Fault
-----------------------------------------------------------------
If I remove the brace-init in the X's initializer list and replace it with
()-init, everything seems to work as expected.
Additionally, X x2{s()} produces the correct result even with brace-init.
Compiled with no warnings or errors:
clang++ brace_ref_init.cpp -o brace_ref_init -std=c++11
On gcc:
g++ brace_ref_init.cpp -o brace_ref_init -std=c++11
gcc doesn't compile it, saying:
-----------------------------------------------------------------
brace_ref_init.cpp: In instantiation of ‘X::X(T&) [with T = S]’:
brace_ref_init.cpp:39:17: required from here
brace_ref_init.cpp:27:18: error: invalid initialization of non-const reference
of type ‘D&’ from an rvalue of type ‘<brace-enclosed initializer list>’
X(T& v) : d{v} {} // brace-init of d causes incorect behaviour
^
brace_ref_init.cpp: In instantiation of ‘X::X(T&) [with T = D]’:
brace_ref_init.cpp:40:19: required from here
brace_ref_init.cpp:27:18: error: invalid initialization of non-const reference
of type ‘D&’ from an rvalue of type ‘<brace-enclosed initializer list>’
-----------------------------------------------------------------
GCC bug report that I think is related:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50025
--
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/20140904/ffade156/attachment.html>
More information about the llvm-bugs
mailing list