'C++ - assigning constexpr char * to static char * copies the string ... is it a bug?
Consider the following program. It simply copies a constexpr const char * to a static const char *. I would expect the pointer to be copied, and be identical. And this is what happens with gcc, clang, and msvc with most options.
However, when using the flag /Zi flag instead of /ZI with a recent msvc, the assert is triggered. I'm wondering if this is a compiler bug or just undefined behavior.
#include <cassert>
constexpr const char *test = "test";
int main()
{
static const char *a = test;
assert(a == test);
}
Here is a compiler explorer link: https://godbolt.org/z/WPz7GPosa. Just changing /Zi to /ZI in the executor tab makes the assert go away.
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
