<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 - Clang crash on C++17 lambda error correction"
   href="https://bugs.llvm.org/show_bug.cgi?id=41622">41622</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang crash on C++17 lambda error correction
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++'17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rtrieu@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In C++17 mode, Clang improperly corrects for an implicitly captured this
pointer in a lambda.  When the lambda is used later, Clang attempts to analyze
the lambda, but fails and crashes.

$ cat test.ii
class S {
  int num;
  void Test() {
    auto lambda = []() { return num; };
    lambda() == 1;
  }
};

$ clang -std=c++17 test.ii
test.ii:4:33: error: 'this' cannot be implicitly captured in this context
    auto lambda = []() { return num; };
                                ^
test.ii:5:14: warning: equality comparison result unused [-Wunused-comparison]
    lambda() == 1;
    ~~~~~~~~~^~~~
Stack dump:
 #4 0x0000000003a85dff HandleLValueMember((anonymous namespace)::EvalInfo&,
clang::Expr const*, (anonymous namespace)::LValue&, clang::FieldDecl const*,
clang::ASTRecordLayout const*) (/usr/local/bin/clang-9+0x3a85dff)
 #5 0x0000000003a7d889 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::PointerExprEvaluator, bool>::Visit(clang::Stmt const*)
(/usr/local/bin/clang-9+0x3a7d889)
 #6 0x0000000003a72ee4 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*)
(/usr/local/bin/clang-9+0x3a72ee4)
 #7 0x0000000003aa6323 (anonymous
namespace)::IntExprEvaluator::VisitCastExpr(clang::CastExpr const*)
(/usr/local/bin/clang-9+0x3aa6323)
 #8 0x0000000003a6b90e Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) (/usr/local/bin/clang-9+0x3a6b90e)
 #9 0x0000000003a846fe EvaluateStmt((anonymous namespace)::StmtResult&,
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*)
(/usr/local/bin/clang-9+0x3a846fe)
#10 0x0000000003a83dda EvaluateStmt((anonymous namespace)::StmtResult&,
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*)
(/usr/local/bin/clang-9+0x3a83dda)
#11 0x0000000003a7085e HandleFunctionCall(clang::SourceLocation,
clang::FunctionDecl const*, (anonymous namespace)::LValue const*,
llvm::ArrayRef<clang::Expr const*>, clang::Stmt const*, (anonymous
namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*)
(/usr/local/bin/clang-9+0x3a7085e)
#12 0x0000000003aa59ee (anonymous namespace)::ExprEvaluatorBase<(anonymous
namespace)::IntExprEvaluator>::handleCallExpr(clang::CallExpr const*,
clang::APValue&, (anonymous namespace)::LValue const*)
(/usr/local/bin/clang-9+0x3aa59ee)
#13 0x0000000003a862fb clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*)
(/usr/local/bin/clang-9+0x3a862fb)
#14 0x0000000003a6b90e Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) (/usr/local/bin/clang-9+0x3a6b90e)
#15 0x0000000003a6da06 EvaluateAsRValue((anonymous namespace)::EvalInfo&,
clang::Expr const*, clang::APValue&) (/usr/local/bin/clang-9+0x3a6da06)
#16 0x0000000003a6f2e8 clang::Expr::isCXX11ConstantExpr(clang::ASTContext
const&, clang::APValue*, clang::SourceLocation*) const
(/usr/local/bin/clang-9+0x3a6f2e8)
#17 0x0000000003a6ee5c clang::Expr::isIntegerConstantExpr(llvm::APSInt&,
clang::ASTContext const&, clang::SourceLocation*, bool) const
(/usr/local/bin/clang-9+0x3a6ee5c)
#18 0x00000000032cffc1 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*,
clang::SourceLocation) (/usr/local/bin/clang-9+0x32cffc1)
#19 0x00000000032d33ce clang::Sema::CheckCompletedExpr(clang::Expr*,
clang::SourceLocation, bool) (/usr/local/bin/clang-9+0x32d33ce)
#20 0x000000000356aad8 clang::Sema::ActOnFinishFullExpr(clang::Expr*,
clang::SourceLocation, bool, bool) (/usr/local/bin/clang-9+0x356aad8)
#21 0x00000000036db041
clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool)
(/usr/local/bin/clang-9+0x36db041)
#22 0x0000000003203bbc
clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext)
(/usr/local/bin/clang-9+0x3203bbc)
#23 0x000000000320231c
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-9+0x320231c)
#24 0x0000000003201e42
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)
(/usr/local/bin/clang-9+0x3201e42)
#25 0x00000000032098a1 clang::Parser::ParseCompoundStatementBody(bool)
(/usr/local/bin/clang-9+0x32098a1)</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>