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

            Bug ID: 48585
           Summary: Clang incorrectly discards constructor of global
                    variable
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

This is an issue that came up with the implementation of constexpr vector and
constexpr string for MSVCs standard library.

The regression is that the constructor of vector (or string) is not executed
properly, which lets the iterator debug machinery of the STL crash. 

A minimal reproducer of he issue is the following code

```
struct container_proxy {};

struct container_base {
    constexpr void alloc_proxy() {
        if (!__builtin_is_constant_evaluated()) {
            proxy = &storage;
        }
    }
    container_proxy storage; // Must be a struct, compiles fine with int
    container_proxy* proxy = nullptr;
};

struct container {
    constexpr container() {
        data.alloc_proxy(); //The call to this function is ommited
    }
    container_base data;
};

container globalVariable;

int main() {
    if (globalVariable.data.proxy == nullptr) {
        return -1;
    }
}
```

I would expect, that global variables that are not constant expressions are
still constructed correctly.

As a side note, the code executes fine if the container_proxy struct is
replaced by a POD type such as int.

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

Reply via email to