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

Conversation

DKLoehr
Copy link
Contributor

@DKLoehr DKLoehr commented May 30, 2025

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.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-clang

Author: Devon Loehr (DKLoehr)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/142158.diff

1 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticGroups.td (+11-7)
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index abb5cefb1d2bb..60c650583801a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -811,7 +811,7 @@ 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.
 
@@ -819,13 +819,17 @@ 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.
 }];
 }
 

@nico nico merged commit 45218e0 into llvm:main May 30, 2025
14 checks passed
abidh added a commit to abidh/llvm-project that referenced this pull request Jun 2, 2025
I observed that docs-clang-html is failing since llvm#142158,

Warning, treated as error:
tools/clang/docs/DiagnosticsReference.rst:18000:Unexpected indentation.
ninja: build stopped: subcommand failed.

Adding an extra empty line here fixes the build.
@abidh
Copy link
Contributor

abidh commented Jun 2, 2025

I noticed docs-clang-html failing after this. I have opened #142387 to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants