Clang supports the -Wglobal-constructors flag which will indicate if a
global constructor is being used. The current goal in libc is to make
the constructors constexpr to prevent this from happening with
straight construction. However, there are many other cases where we can
emit a constructor that this won't catch. This should give warning if
someone accidentally introduces a global constructor.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
I'm in favour. Definitely want this for the GPU targets even if the others want to stay warning-free
Comment Actions
Yes,
/home/jhuber/Documents/llvm/llvm-project/libc/src/unistd/getopt.cpp:184:22: warning: declaration requires a global constructor [-Wglobal-constructors] 184 | static GetoptContext ctx{ | ^ ~ 185 | &impl::optarg, &impl::optind, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 186 | &impl::optopt, &optpos, | ~~~~~~~~~~~~~~~~~~~~~~~ 187 | impl::opterr, reinterpret_cast<FILE *>(__llvm_libc::stderr)}; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/jhuber/Documents/llvm/llvm-project/libc/src/__support/File/linux/file.cpp:160:18: warning: declaration requires a global destructor [-Wglobal-constructors] 160 | static LinuxFile StdIn(0, stdin_buffer, STDIN_BUFFER_SIZE, _IOFBF, false, | ^ /home/jhuber/Documents/llvm/llvm-project/libc/src/__support/File/linux/file.cpp:166:18: warning: declaration requires a global destructor [-Wglobal-constructors] 166 | static LinuxFile StdOut(1, stdout_buffer, STDOUT_BUFFER_SIZE, _IOLBF, false, | ^ /home/jhuber/Documents/llvm/llvm-project/libc/src/__support/File/linux/file.cpp:171:18: warning: declaration requires a global destructor [-Wglobal-constructors] 171 | static LinuxFile StdErr(2, nullptr, STDERR_BUFFER_SIZE, _IONBF, false, | ^ 3 warnings generated.