[llvm-bugs] [Bug 48732] New: Clang is too strict on object lifetime for automatic storage duration

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 12 14:27:42 PST 2021


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

            Bug ID: 48732
           Summary: Clang is too strict on object lifetime for automatic
                    storage duration
           Product: clang
           Version: trunk
          Hardware: PC
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: minatsuh at microsoft.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Behavior displayed in https://godbolt.org/z/n5Wenn

Reproducing code repeated here: 
template <typename T>
constexpr void f(T& t) {
    t.~T();
}

struct S {
    constexpr ~S() { }
};

constexpr int g() {
    {
        // This should be fine, provided there are no more reads of
        // 'i' before a new object lifetime is created.
        int i = 0;
        f(i);
    }
    {
        // This should be UB: S::~S() is a non-trivial dtor.
        S s{};
        f(s);
    }
    return 0;
}

static_assert(g() == 0);

Relevant Standardese: 
* http://eel.is/c++draft/basic.life#5 
* http://eel.is/c++draft/basic.life#9

Currently, Clang errors on the first block of code using int i, though I
believe the first block of code should be fine as int does not have a
non-trivial destructor (http://eel.is/c++draft/basic.life#9).  Note that the
second block should produce an error (which Clang does) as struct S does have a
non-trivial destructor.

-- 
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/20210112/8d1e6e31/attachment.html>


More information about the llvm-bugs mailing list