内联函数的局部static/thread_local变量?

And*_*zos 13 c++ c++11 c++14

如果我有一个静态局部变量或thread_local局部变量,它在一个内联函数中,在不同的翻译单元中定义,在最终的程序中它们是否由标准保证具有相同的地址?

// TU1:
inline int* f() { static int x; return &x; }
extern int* a;
void sa() { a = f(); }

// TU2:
inline int* f() { static int x; return &x; }
extern int* b;
void sb() { b = f(); }

// TU3:
int *a, *b;
void sa();
void sb();
int main() { sa(); sb(); return a == b; }
Run Code Online (Sandbox Code Playgroud)

以上总是会返回1吗?

Ker*_* SB 10

是的,它始终是同一个对象.按[dcl.fct.spec]/4:

inline具有外部链接的功能在所有翻译单元中应具有相同的地址.甲static在局部变量extern inline函数总是指相同的对象.extern inline函数体内定义的类型在每个翻译单元中都是相同的类型.