[all-commits] [llvm/llvm-project] 004a5f: Enable -Wunique-object-duplication inside template...

Devon Loehr via All-commits all-commits at lists.llvm.org
Fri Feb 14 04:18:45 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 004a5fea236c5b890fb2aff1ab2ceb0f0ed82e74
      https://github.com/llvm/llvm-project/commit/004a5fea236c5b890fb2aff1ab2ceb0f0ed82e74
  Author: Devon Loehr <DKLoehr at users.noreply.github.com>
  Date:   2025-02-14 (Fri, 14 Feb 2025)

  Changed paths:
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Sema/SemaDecl.cpp
    M clang/test/SemaCXX/unique_object_duplication.h

  Log Message:
  -----------
  Enable -Wunique-object-duplication inside templated code (#125902)

Followup to #125526. This allows the unique object duplication warning
to fire on code inside of templates. Previously, it was disabled there
to prevent false positives if the template was never instantiated.

The patch has two parts: first, we move the check from
`FinalizeDeclaration` (which is only called during parsing) to
`CheckCompleteVariableDeclaration` (which is also called during template
instantiation). Since the code we're moving is fairly bulky, we abstract
it into a separate function for convenience.

Second, we disable the warning during template parsing, and add a check
later to see if the variable we're acting on on originated from a
template. If so, it has the potential to be duplicated just like an
inline variable.

## Testing
Unit tests for template have been added to the existing test suite. To
evaluate the patch on real code, I ran it on chromium and on clang
itself. As expected, in both cases we got strictly more warnings than
before. I manually looked through each new warning, and they all seemed
legitimate.

In chromium, we found [79 new warnings across 55
files](https://github.com/user-attachments/files/18676635/new_warnings_chromium.txt),
mostly in third-party code (for a total of 234 warnings across 137
files). In clang, we found [8 new warnings across 6
files](https://github.com/user-attachments/files/18676658/new_warnings_clang.txt),
for a total of 17 warnings across 11 files.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list