<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - type conversion operator was not invoked during initialization"
href="https://bugs.llvm.org/show_bug.cgi?id=36973">36973</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>type conversion operator was not invoked during initialization
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>guojiufu@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>For below code, clang generates incorrect result because of the member function
function of one operator missed from AST.
----------------t.cpp------------------
struct A {
float x;
int y;
˜A() {}
operator float() const {
return x + 1.2;
}
operator int() const {
return x + 3;
}
};
int main(){
A x=A({A()});///---> if A({A(),A()}), two elements are all initialzed the
result is ok
return x.x;
}
----------------------------------------
clang++ -std=c++11 t.cpp
./a.out
echo $?
0 ===> should be 1
-------------------------------------------------
AST looks like:
| `-VarDecl 0x12919258 <col:3, col:14> col:5 used x 'struct A' cinit
| `-ExprWithCleanups 0x12919950 <col:7, col:14> 'struct A'
| `-CXXConstructExpr 0x12919918 <col:7, col:14> 'struct A' 'void (const
struct A &) noexcept' elidable
| `-MaterializeTemporaryExpr 0x12919900 <col:7, col:14> 'const struct
A' lvalue
| `-ImplicitCastExpr 0x129198e8 <col:7, col:14> 'const struct A'
<NoOp>
| `-CXXFunctionalCastExpr 0x129198c0 <col:7, col:14> 'struct A'
functional cast to struct A <ConstructorConversion>
| `-CXXBindTemporaryExpr 0x129198a0 <col:7, col:14> 'struct A'
(CXXTemporary 0x12919898)
| `-CXXConstructExpr 0x12919860 <col:7, col:14> 'struct A'
'void (const struct A &) noexcept'
| `-InitListExpr 0x12919670 <col:9, col:13> 'const struct A'
lvalue
| `-MaterializeTemporaryExpr 0x12919658 <col:10, col:12>
'const struct A' lvalue ======> here missing one member function call
| `-ImplicitCastExpr 0x12919640 <col:10, col:12> 'const
struct A' <NoOp>
| `-CXXBindTemporaryExpr 0x129195d8 <col:10, col:12>
'struct A' (CXXTemporary 0x129195d0)
| `-CXXTemporaryObjectExpr 0x12919598 <col:10,
col:12> 'struct A' 'void (void) noexcept' zeroing
:
| `-InitListExpr 0x12919760 <col:9, col:18> 'const struct
A'
| |-ImplicitCastExpr 0x12919840 <col:10, col:12>
'float' <UserDefinedConversion>
| | `-CXXMemberCallExpr 0x12919810 <col:10, col:12>
'float' ===========================
| | `-MemberExpr 0x129197d8 <col:10, col:12> '<bound
member function type>' .operator float 0x12918c48
| | `-ImplicitCastExpr 0x129197c0 <col:10, col:12>
'const struct A' <NoOp>
| | `-CXXBindTemporaryExpr 0x129195e8 <col:10,
col:12> 'struct A' (CXXTemporary 0x129195e0)
| | `-CXXTemporaryObjectExpr 0x129195a8
<col:10, col:12> 'struct A' 'void (void) noexcept' zeroing</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>