[PATCH] D54222: [clang-tidy] Add a check to detect returning static locals in public headers

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 22:36:43 PDT 2020


rsmith added inline comments.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone-problematic-statics.rst:7-8
+Detects functions defined in headers that return the address of a static
+local variable. These are not guaranteed to have the same addresss across
+shared libraries and could be problematic for plugins.
+
----------------
The C++ language rules do guarantee that such static locals have the same address throughout the entire program. Should this warning check the symbol visibility / `dllexport`edness? People are going to learn the wrong thing if we give them this diagnostic without any further explanation.

If the concern is plugins loaded with `RTLD_LOCAL`, sharing C++ interfaces across an `RTLD_LOCAL` boundary is pretty fundamentally broken, and this is far from the only way in which it goes wrong. It might be better to warn on all non-`RTLD_GLOBAL` calls to `dlopen` from C++ code...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54222/new/

https://reviews.llvm.org/D54222



More information about the cfe-commits mailing list