[llvm-bugs] [Bug 40044] New: destructor of lambda called twice when handling an exception

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 16 07:30:08 PST 2018


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

            Bug ID: 40044
           Summary: destructor of lambda called twice when handling an
                    exception
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: yan_avlasov at hotmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following code should print 1. It prints 0. Works with clang 7

#include <iostream>
static int s_count = 0;

template <typename T>
void Foo(T&& t) {
  throw 1;
}

int main() {
  struct Tracker {
    Tracker() { ++s_count; }
    Tracker(const Tracker&) { ++s_count; }
    Tracker(Tracker&& t) { ++s_count; t.moved_ = true; }
    ~Tracker() { if (!moved_) --s_count; }
    bool moved_ = false;
  };


  Tracker t;
  try {
    Foo([t]() {});
  } catch (...) {
    std::cout << s_count << std::endl;
  }
  return 0;
}

-- 
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/20181216/b65ff5a0/attachment.html>


More information about the llvm-bugs mailing list