Skip to content

Commit 45218e0

Browse files
authored
[NFC] Tweak docs for unique-object-duplication warning (#142158)
This improves the documentation for the unique-object-duplication warning. It clarifies the conditions for the warning to fire, provides clearer instructions on how to resolve it, and adjusts wording to be more precise.
1 parent f8d3bdf commit 45218e0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -811,21 +811,25 @@ changes to one object won't affect the others, the object's initializer will run
811811
once per copy, etc.
812812

813813
Specifically, this warning fires when it detects an object which:
814-
1. Appears in a header file (so it might get compiled into multiple libaries), and
814+
1. Is defined as ``inline`` in a header file (so it might get compiled into multiple libaries), and
815815
2. Has external linkage (otherwise it's supposed to be duplicated), and
816816
3. Has hidden visibility.
817817

818818
As well as one of the following:
819819
1. The object is mutable, or
820820
2. The object's initializer definitely has side effects.
821821

822-
The warning is best resolved by making the object ``const`` (if possible), or by explicitly
823-
giving the object non-hidden visibility, e.g. using ``__attribute((visibility("default")))``.
824-
Note that all levels of a pointer variable must be constant; ``const int*`` will
825-
trigger the warning because the pointer itself is mutable.
822+
The warning can be resolved by removing one of the conditions above. In rough
823+
order of preference, this may be done by:
824+
1. Marking the object ``const`` (if possible)
825+
2. Moving the object's definition to a source file
826+
3. Giving the object non-hidden visibility, e.g. using ``__attribute((visibility("default")))``.
826827

827-
This warning is currently disabled on Windows since it uses import/export rules
828-
instead of visibility.
828+
Note that for (2), all levels of a pointer variable must be constant;
829+
``const int*`` will trigger the warning because the pointer itself is mutable.
830+
831+
This warning is not yet implemented for Windows, since Windows uses
832+
import/export rules instead of visibility.
829833
}];
830834
}
831835

0 commit comments

Comments
 (0)