Solved: Why does clang-tidy’s modernize-use-emplace miss this warning?

Question:

a.cpp:
clang-tidy -config=”{Checks: ‘modernize-use-emplace’}” a.cpp
clang-tidy –version
clang-tidy wiki

Best Answer:

Short answer: This behavior is due to bug 56721 in clang-tidy.
Long answer, based on my comment on that bug:
The bug relates to how reference is declared in the container. That in turn causes clang-tidy to not realize that the return value of the accessor is an instance of a relevant container.
The core of UseEmplaceCheck.cpp is:
Using the example from the question, the following simplified matcher (which can be passed to clang-query) will report the non-nested case, as expected:
Reports:
However, to get it to match the nested case (when compiling with GCC-9.3.0 headers), it must be changed to:
Reports:
That is, the type is no longer a cxxRecordDecl, and its name is a long template-id. That template-id is derived from the code used to declare std::vector::reference in the headers. It should be semantically equivalent to std::pair<int, int>, but that equivalence is evidently obscured from clang-tidy here.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com