For header files that pass the -header-filter, the
modernize-concat-nested-namespaces check does not generate the expected
warning and fix for un-concatenated namespaces. This diff fixes it.
https://bugs.llvm.org/show_bug.cgi?id=41670
This diff also enables the check for c++2a.
Test Plan:
Extended unit test
```
make check-clang-tools/fast
```
Manual testing previously:
```
====a.h===
namespace foo {
namespace bar {
namespace baz {
struct S {};
}
}
}
========
====a.cpp====
namespace foo {
namespace bar {
namespace baz {
void foo(const S&) {}
}
}
}
int main () {
return 0;
}
========
$ /clang-tidy -p sample/compile_commands.json -checks="modernize-concat-nested-namespaces" -header-filter="a.h" sample/a.cpp
4 warnings generated.
sample/a.h:5:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
namespace foo {
^~~~~~~~~~~~~~~
namespace foo::bar::baz
sample/a.cpp:5:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
namespace foo {
^~~~~~~~~~~~~~~
namespace foo::bar::baz
```
Ran the check on the llvm code base:
```
./llvm-project/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -p \
llvm-project/llvm llvm-project/llvm -header-filter='llvm-project/llvm.*' \
-checks="-*,modernize-concat-nested-namespaces" -extra-arg='--std=c++17' \
-j 8
```
The entire output is 8.4M. Generated 33k warnings, among which 275 on `.cpp`
files, the rest on 447 different headers. Below is a list of the number of
duplicate warnings for a particular header:
```
... ...
104 llvm/include/llvm/BinaryFormat/Wasm.h
106 llvm/include/llvm/Support/EndianStream.h
117 llvm/include/llvm/Support/Path.h
120 llvm/include/llvm/BinaryFormat/COFF.h
140 llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h
142 llvm/include/llvm/BinaryFormat/ELF.h
146 llvm/include/llvm/DebugInfo/CodeView/RecordSerialization.h
162 llvm/include/llvm/CodeGen/MIRYamlMapping.h
163 llvm/include/llvm/DebugInfo/CodeView/CodeView.h
168 llvm/include/llvm/BinaryFormat/MachO.h
172 llvm/lib/Target/AMDGPU/SIDefines.h
225 llvm/include/llvm/Object/SymbolicFile.h
250 llvm/include/llvm/Object/Error.h
292 llvm/include/llvm/Support/AArch64TargetParser.h
293 llvm/include/llvm/Support/ARMTargetParser.h
302 llvm/include/llvm/DebugInfo/CodeView/CodeViewError.h
321 llvm/include/llvm/Support/YAMLTraits.h
347 llvm/utils/unittest/googletest/include/gtest/gtest-printers.h
347 llvm/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h
347 llvm/utils/unittest/googletest/include/gtest/internal/gtest-filepath.h
347 llvm/utils/unittest/googletest/include/gtest/internal/gtest-linked_ptr.h
347 llvm/utils/unittest/googletest/include/gtest/internal/gtest-string.h
384 llvm/include/llvm/Support/CFGUpdate.h
498 llvm/include/llvm/CodeGen/RuntimeLibcalls.h
504 llvm/include/llvm/CodeGen/TargetCallingConv.h
514 llvm/include/llvm/CodeGen/ISDOpcodes.h
530 llvm/include/llvm/CodeGen/MachineOutliner.h
620 llvm/include/llvm/CodeGen/PBQPRAConstraint.h
863 llvm/include/llvm/Support/FileSystem.h
938 llvm/include/llvm/Support/Mutex.h
1389 llvm/include/llvm/Support/RWMutex.h
1393 llvm/include/llvm/IR/CallingConv.h
2037 llvm/include/llvm/Support/Endian.h
2308 llvm/include/llvm/Support/Host.h
2380 llvm/include/llvm/Support/raw_ostream.h
2465 llvm/include/llvm/Support/SwapByteOrder.h
6903 llvm/include/llvm/ADT/Hashing.h
```
This seems excessive, but the `--header-filter` option (along with
`--fix`) would make this more manageable--a user could go through
a large code base directory by directory; alternatively, using the
`--fix` option would apply the fix and avoid a duplicate warning at the
same spot.