@@ -694,7 +694,36 @@ def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess",
694694 NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>;
695695def StaticInInline : DiagGroup<"static-in-inline">;
696696def StaticLocalInInline : DiagGroup<"static-local-in-inline">;
697- def UniqueObjectDuplication : DiagGroup<"unique-object-duplication">;
697+ def UniqueObjectDuplication : DiagGroup<"unique-object-duplication"> {
698+ code Documentation = [{
699+ Warns when objects which are supposed to be globally unique might get duplicated
700+ when built into a shared library.
701+
702+ If an object with hidden visibility is built into a shared library, each instance
703+ of the library will get its own copy. This can cause very subtle bugs if there was
704+ only supposed to be one copy of the object in question: singletons aren't single,
705+ changes to one object won't affect the others, the object's initializer will run
706+ once per copy, etc.
707+
708+ Specifically, this warning fires when it detects an object which:
709+ 1. Appears in a header file (so it might get compiled into multiple libaries), and
710+ 2. Has external linkage (otherwise it's supposed to be duplicated), and
711+ 3. Has hidden visibility.
712+
713+ As well as one of the following:
714+ 1. The object is mutable, or
715+ 2. The object's initializer definitely has side effects.
716+
717+ The warning is best resolved by making the object ``const`` (if possible), or by explicitly
718+ giving the object non-hidden visibility, e.g. using ``__attribute((visibility("default")))``.
719+ Note that all levels of a pointer variable must be constant; ``const int*`` will
720+ trigger the warning because the pointer itself is mutable.
721+
722+ This warning is currently disabled on Windows since it uses import/export rules
723+ instead of visibility.
724+ }];
725+ }
726+
698727def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">;
699728def StaticFloatInit : DiagGroup<"static-float-init", [GNUStaticFloatInit]>;
700729// Allow differentiation between GNU statement expressions in a macro versus
0 commit comments