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

    <tr>
        <th>Summary</th>
        <td>
            `clang-tidy` shows some warnings from inside a macro coming from a system header
        </td>
    </tr>

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

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

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

<pre>
    I'm using GoogleTest and GoogleMock. The macro `TEST` from GoogleTest behaves correctly, and it does not give any error, as it comes from a system header. But the macros `MATCHER` and `MATCHER_P` don't: they give me errors from `clang-tidy` at the use point of the macro. I get `modernize-use-trailing-return-type` warnings, as well as `cppcoreguidelines-avoid-const-or-ref-data-members` coming from these macros.

I've checked my `compile_commands.json`, the include path for both `<gtest/gtest.h>`(where the TEST macro comes from) and `<gmock/gmock.h>` (where the MATCHER and MATCHER_P macros are defined) is the same, and it is marked as `-isystem`.

Code example:
The trailing-return-type warning is flagged on the `PointEq` word, and the const-or-ref-data-members on the `p` word.
```cpp
#include <gtest/gtest.h>
#include <gmock/gmock.h>

MATCHER_P(PointEq, p, "stuff") {}
```

Here is the macro expansion, with comments marking the points where the warnings are flagged:
```cpp
template<typename p_type>
class PointEqMatcherP : public ::testing ::internal ::MatcherBaseImpl<PointEqMatcherP<p_type>>
{
public:
    using PointEqMatcherP ::MatcherBaseImpl ::MatcherBaseImpl;

 template<typename arg_type>
    class gmock_Impl : public ::testing ::MatcherInterface<const arg_type&>
    {
    public:
 explicit gmock_Impl(p_type gmock_p0) : p(::std ::forward<p_type>(gmock_p0)) {}

// On the next line, a trailing return type warning
        bool MatchAndExplain(const arg_type& arg, ::testing ::MatchResultListener* result_listener) const override;

        void DescribeTo(::std ::ostream* gmock_os) const override { *gmock_os << FormatDescription(false); }

        void DescribeNegationTo(::std ::ostream* gmock_os) const override { *gmock_os << FormatDescription(true); }

// On the next line, a const-qualified data member warning
        const p_type p;

    private:
// On the next line, trailing return type warning
        ::std ::string FormatDescription(bool negation) const
 {
            ::std ::string gmock_description;
 gmock_description = ("stuff");
            if (!gmock_description.empty())
            {
                return gmock_description;
            }
            return ::testing ::internal ::FormatMatcherDescription(
                negation,
 "PointEq",
                {"p"},
 ::testing ::internal ::UniversalTersePrintTupleFieldsToStrings(::std ::tuple<p_type>(p)));
        }
    };
};

template<typename p_type>
// On the next line, trailing return type warning
inline PointEqMatcherP<p_type> PointEq(p_type gmock_p0)
{
    return PointEqMatcherP<p_type>(gmock_p0);
}

template<typename p_type>
template<typename arg_type>
// On the next line, trailing return type warning
bool PointEqMatcherP<p_type>::gmock_Impl<arg_type>::MatchAndExplain(
    const arg_type& arg,
    ::testing ::MatchResultListener* result_listener __attribute__((unused))) const
{
}
```

Output of `clang-tidy --version`:
```
Ubuntu LLVM version 18.1.3
  Optimized build.
```

Operating system:
Ubuntu 22.04 docker container running on a Ubuntu 20.04 host. `clang-tidy` is `clang-tidy-18` from the LLVM apt repository.

This was initially found using `clangd`, and I've reported an issue over there: https://github.com/clangd/clangd/issues/2000.
With the non-macro-expanded example code above in a file `test.cpp`, the correct `-isystem` flags in the compilation database, and the following command line, these issues are easy to reproduce:
```bash
clang-tidy --system-headers=0 --checks="modernize-use-trailing-return-type,cppcoreguidelines-avoid-const-or-ref-data-members" test.cpp
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WEtv4zgS_jX0pSBDphM_Dj4kTrLTQPd2Y8azewxosWxxmiI1JBXH8-sXRVG2_Eg6sw2MEEQSTdbjqyoWPwnv1dYgLtjtPbt9GIgmlNYt6lJpVde4E86hGayt3C8-MT6toPHKbOFf1m41rtAHEEam1y-2-D6EVYlQicJZYJN89fjbik1y2Dhb9RetsRQv6KGwzmER9J7xZZSkAkiLHowNsFUvCMLsAZ2zLs7wNKGwFfpWpAC_9wErKFFIdEO4bwKEzgJPJny5Wy1_efyVrCAFx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