[llvm-bugs] [Bug 33999] New: Double destruction of object created in for loop condition

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 31 01:06:24 PDT 2017


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

            Bug ID: 33999
           Summary: Double destruction of object created in for loop
                    condition
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: stephane.zimmermann at trust-in-soft.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following code:

extern "C" int printf(const char *, ...);

struct Foo {
    Foo() {
        printf("CONSTRUCTOR\n");
    }
    ~Foo() {
        printf("DESTRUCTOR\n");
    }

    operator bool() {
        static int guard = 0;
        ++guard;
        return guard < 3;
    }
};

int main(void) {
    for( ; Foo f {}; 0)
        continue;
}

displays:

CONSTRUCTOR
DESTRUCTOR
DESTRUCTOR
CONSTRUCTOR
DESTRUCTOR
DESTRUCTOR
CONSTRUCTOR
DESTRUCTOR

In the two iterations of the loop the object in condition is destroyed two
times. This does not happen if the increment is empty or without the
"continue;" statement.

-- 
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/20170731/a8011a6d/attachment-0001.html>


More information about the llvm-bugs mailing list