[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 23 13:57:21 PDT 2025


vinay-deshmukh wrote:

As of https://github.com/llvm/llvm-project/pull/131485/commits/0ab296549a59d8aac3c4ef6326924959d65cef01 :


while trying to constexpr things (and remove virtual destructor to make Test a literal type which can be `constexpr`-ed)

fails with:

```
In file included from /home/runner/work/llvm-project/llvm-project/libc/test/UnitTest/LibcTest.cpp:9:
/home/runner/work/llvm-project/llvm-project/libc/test/UnitTest/LibcTest.h:115:7: warning: '__llvm_libc_21_0_0_git::testing::Test' has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]
  115 | class Test {
      |       ^
/home/runner/work/llvm-project/llvm-project/libc/test/UnitTest/LibcTest.h:130:26: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  130 |   constexpr static void *addTest(Test *T) {
      |                          ^~~~~~~
/home/runner/work/llvm-project/llvm-project/libc/test/UnitTest/LibcTest.h:131:9: note: read of non-constexpr variable 'End' is not allowed in a constant expression
  131 |     if (End == nullptr) {
      |         ^
/home/runner/work/llvm-project/llvm-project/libc/test/UnitTest/LibcTest.h:240:16: note: declared here
  240 |   static Test *End;
      |                ^
1 warning and 1 error generated.
```

I think wrapping with pragma may be the only way here short of disabling the warning for the whole test suite

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


More information about the libc-commits mailing list