[libc-commits] [libc] [libc]: Add `-Wglobal-constructors` for libc tests (PR #131485)

Vinay Deshmukh via libc-commits libc-commits at lists.llvm.org
Sun Mar 30 06:52:25 PDT 2025


vinay-deshmukh wrote:

FWIW: the reason [6b558fb](https://github.com/llvm/llvm-project/pull/131485/commits/6b558fb81bfc129455e06d408b6adc03a42aa7be) didn't work is:

https://stackoverflow.com/a/5804024

```
 however, it is not actually guaranteed that this constructor is ever executed unless the object is ODR-used, and the order of initialisation is unsequenced with respect to other initialisations (= hard to predict).

```


One way to ODR-use it is put that `static Type instance;` in namespace scope, but then the error for `Requires a global destructor` shows up, at which point, we are back where we started. And I believe the original declaration/definition is at that scope, to ensure ODR use.


I managed to figure out how to use `_Pragma` correctly, which allows us to embed `#pragma` to wrap those "global" constructors with "disable warnings for global constructor", so the constructor runs now, and the tests should be running now.


https://github.com/llvm/llvm-project/pull/131485


More information about the libc-commits mailing list