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