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

            Bug ID: 47805
           Summary: constexpr evaluator incorrectly claims double delete
                    with function parameter
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangb...@nondot.org
          Reporter: da...@doublewise.net
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

The following translation unit

```
struct S {
        int * m_ptr;

        constexpr S():
                m_ptr(new int())
        {
        }
        constexpr S(S && other) noexcept:
                m_ptr(other.m_ptr)
        {
                other.m_ptr = nullptr;
        }
        constexpr ~S() noexcept {
                delete m_ptr;
        }
};

constexpr bool test(S v) {
        auto x = static_cast<S &&>(v);
        return true;
}

static_assert(test(S()));
```

is rejected with 

```
<source>:23:15: error: static_assert expression is not an integral constant
expression

static_assert(test(S()));

              ^~~~~~~~~

<source>:14:3: note: delete of pointer that has already been deleted

                delete m_ptr;

                ^

<source>:23:20: note: in call to '&S()->~S()'

static_assert(test(S()));

                   ^

1 error generated.

Compiler returned: 1
```

This problem does not occur if `v` is turned into a local variable instead of a
function parameter.

See it live: https://godbolt.org/z/hcv88h

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to