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: unassignedclangb...@nondot.org
          Reporter: stephane.zimmerm...@trust-in-soft.com
                CC: dgre...@apple.com, llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to