<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/93386>93386</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [[gsl::Pointer]] and [[clang::lifetimebound]] produce duplicate (or near-duplicate) warnings for some code locations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          pkasting
      </td>
    </tr>
</table>

<pre>
    `[[gsl::Pointer]]` and `[[clang::lifetimebound]]` each catch unique lifetime bugs (demonstration of non-overlappingness: https://godbolt.org/z/4W7G5n48r). Therefore, both are desirable when applicable. However, applying both sometimes results in multiple warnings about the same location:
```
#include <stddef.h>
#include <array>

struct [[gsl::Pointer]] S {
 template <size_t N>
  S(const std::array<int, N>& a [[clang::lifetimebound]]) : p(a.data()) {}

  const int* p;
};

S f() {
  std::array a{1, 2, 3};
  return S(a);  // Two instances of -Wreturn-stack-address, not just one
}

auto s = S(std::array{1, 2, 3});  // Both -Wdangling-gsl and -Wdangling, not just one
```
Live repro: https://godbolt.org/z/K4zc3WE73

Especially in the first case, it's confusing to see the exact same error for the same location issued repeatedly. I think the compiler should issue just one warning here.

The second case is more understandable, as it's technically two distinct warnings -- but one is controlled by the other, they are firing at the exact same location, and they are effectively warning about the same issue. Ideally this would also result in just one warning.

This is not a huge deal, but it can confuse coders about whether they have multiple distinct issues to fix. More importantly in my case, it requires tweaks to nocompile tests to deal with the multiple diagnostics being emitted, which makes the tests more brittle.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVd2O2zgPfRrlhkiQyM7PXORiMtN8X7E_WKAF5nIhS7Stjiy5Ep00ffoF5UySptvFAIGTyBR5eHhIqpRs4xG3YrkTy-eJGqgNcdu_qkTWN5MqmNNWrOb59a5JThSPonj8K1hPGMXymT-rOShv4GKmnfLNaOhsjWQ7r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