Skip to content

[NFC] Tweak docs for unique-object-duplication warning #142158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -811,21 +811,25 @@ changes to one object won't affect the others, the object's initializer will run
once per copy, etc.

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

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

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

This warning is currently disabled on Windows since it uses import/export rules
instead of visibility.
Note that for (2), all levels of a pointer variable must be constant;
``const int*`` will trigger the warning because the pointer itself is mutable.

This warning is not yet implemented for Windows, since Windows uses
import/export rules instead of visibility.
}];
}

Expand Down
Loading