是否保证在 std::string 之前初始化指向字符串文字的指针?

Is a pointer to string literal guaranteed to be initialized before a std::string?

//file1.cpp
extern const char* foo;
std::string bar = foo;

//file2.cpp
const char* foo = "foo";

标准保证bar初始化为"foo"吗?或者它可以在 foo 被设置和构造函数中的段错误之前初始化,即 SIOF 的情况?

常量初始化保证首先发生(foo 在这种情况下)。

所以

Is bar guaranteed by the standard to be initialized to "foo"?

是的。

Or could it be initialized before foo gets set and segfault in the constructor i.e. a case of SIOF?

没有

来源:https://en.cppreference.com/w/cpp/language/constant_initialization