[llvm-bugs] [Bug 36973] New: type conversion operator was not invoked during initialization

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Apr 1 20:01:00 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=36973

            Bug ID: 36973
           Summary: type conversion operator was not invoked during
                    initialization
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: guojiufu at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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

-- 
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/20180402/33482aa9/attachment.html>


More information about the llvm-bugs mailing list