http://llvm.org/bugs/show_bug.cgi?id=15330

            Bug ID: 15330
           Summary: Memory leak is produced due to an appropriate "delete
                    operator" is not called for a "new" statement which
                    throws an exception while another template version of
                    "operator delete" is declared
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

GCC doesn't produce a memory leak, but it does in clang trunk

$ clang++ --version && cat main.cpp && clang++ main.cpp -o main && ./main
clang version 3.3 (trunk 175738)
Target: i386-pc-linux-gnu
Thread model: posix


#include <iostream>

static bool freed = true;

void * operator new (unsigned int, const bool &) throw() {
  return freed = false, (void *)!0;
}

void operator delete (void *, const bool &) throw() {
  freed = true;
}
#if 1 // This declaration makes a trick: no one delete is called
template <typename T>
void operator delete (void *, const T &) {
  freed = true;
}
#endif

int main() {
  try {
    struct Throwable { Throwable() { throw int(-1); } };
    new (!0) Throwable;
  } catch(...) {
    if (!freed)  { std::cout << "memory leak detected" << std::endl; }
  }
  return 0;
}



memory leak detected

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to