Skip to content

Commit 6356a4f

Browse files
committed
Add documentation and a release note
1 parent 31ae747 commit 6356a4f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ Improvements to Clang's diagnostics
116116
- Improve the diagnostics for deleted default constructor errors for C++ class
117117
initializer lists that don't explicitly list a class member and thus attempt
118118
to implicitly default construct that member.
119+
- The ``-Wunique-object-duplication`` warning has been added to warn about objects
120+
which are supposed to only exist once per program, but may get duplicated when
121+
built into a shared library.
119122

120123
Improvements to Clang's time-trace
121124
----------------------------------

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,36 @@ def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess",
694694
NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>;
695695
def StaticInInline : DiagGroup<"static-in-inline">;
696696
def 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+
698727
def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">;
699728
def StaticFloatInit : DiagGroup<"static-float-init", [GNUStaticFloatInit]>;
700729
// Allow differentiation between GNU statement expressions in a macro versus

0 commit comments

Comments
 (0)