<html>
<head>
<base href="http://llvm.org/bugs/" />
</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 --- - X() = default has poor code generation"
href="http://llvm.org/bugs/show_bug.cgi?id=19092">19092</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>X() = default has poor code generation
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>howard.hinnant@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider this code:
#include <vector>
#include <string>
class X
{
std::vector<int> v_;
std::string s_;
bool q_ = false;
public:
#if 0
X() {}
#elif 1
X() = default;
#endif
};
X
test_default()
{
return X{};
}
With a user-defined default constructor, test_default() (at -O3) generates:
__Z12test_defaultv: ## @_Z12test_defaultv
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp11:
.cfi_def_cfa_offset 16
Ltmp12:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp13:
.cfi_def_cfa_register %rbp
movb $0, 48(%rdi)
movq $0, 40(%rdi)
movq $0, 32(%rdi)
movq $0, 24(%rdi)
movq $0, 16(%rdi)
movq $0, 8(%rdi)
movq $0, (%rdi)
movq %rdi, %rax
popq %rbp
ret
.cfi_endproc
But if I instead use the presumably preferred X() = default technique to
generate the default constructor, I am severely penalized (by a factor of 2):
.section __TEXT,__text,regular,pure_instructions
.globl __Z12test_defaultv
.align 4, 0x90
__Z12test_defaultv: ## @_Z12test_defaultv
.cfi_startproc
## BB#0: ## %entry
pushq %rbp
Ltmp0:
.cfi_def_cfa_offset 16
Ltmp1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
movq $0, 48(%rdi)
movq $0, 40(%rdi)
movq $0, 32(%rdi)
movq $0, 24(%rdi)
movq $0, 16(%rdi)
movq $0, 8(%rdi)
movq $0, (%rdi)
movb $0, 48(%rdi)
movq $0, 40(%rdi)
movq $0, 32(%rdi)
movq $0, 24(%rdi)
movq $0, 16(%rdi)
movq $0, 8(%rdi)
movq $0, (%rdi)
movq %rdi, %rax
popq %rbp
retq
.cfi_endproc
.subsections_via_symbols
This makes me hesitate to recommend "= default". It doesn't look ready for
prime time.</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>