This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Enable modernize-concat-nested-namespaces also on headers
ClosedPublic

Authored by DmitryPolukhin on Feb 26 2021, 9:31 AM.

Details

Summary

For some reason the initial implementation of the check had an explicit check
for the main file to avoid being applied in headers. This diff removes this
check and add a test for the check on a header.

Similar approach was proposed in D61989 but review there got stuck.

Test Plan: added new test case

Diff Detail

Event Timeline

DmitryPolukhin created this revision.Feb 26 2021, 9:31 AM
DmitryPolukhin requested review of this revision.Feb 26 2021, 9:31 AM
njames93 added inline comments.Feb 26 2021, 9:49 AM
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
8

This fix line isn't actually contributing to the test.
Perhaps a better case, assuming clang-format doesn't update the comment, would be:

// CHECK-FIXES: void t();
// CHECK-FIXES-NEXT: } namespace nn1
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
4

Why do we explicitly run on c++2b and not c++20? I understand there is no framework in place for using -std=c++17-or-later when header files are modified.

Comments resolved

DmitryPolukhin marked an inline comment as done.Feb 26 2021, 10:18 AM

@njames93 thank you for quick response and good suggestion!

clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
4

There is no good reason, I just took highest current version. Changed to c++20.

DmitryPolukhin marked an inline comment as done.Feb 26 2021, 10:18 AM
njames93 added inline comments.Feb 26 2021, 11:08 AM
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
4

This is just me rambling, but i think we should think about introducing a test mode to clang tidy, where fixes can be applied to a test directory and maybe try and make use of the verify diagnostic consumer. The current implementation works, but is very rough round the edges.

Use -DAG checks to make test stable

@aaron.ballman @alexfh @njames93 - friendly ping, please take a look!

njames93 accepted this revision.Mar 14 2021, 5:12 AM

Is DAG required because the header file warnings are printed in a different order depending on things like platform?

This revision is now accepted and ready to land.Mar 14 2021, 5:12 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 14 2021, 5:12 AM

I think the implicit question is: won't this regress headers that are meant to be compatible with earlier standards?
Did the original review mention anything about this?

I think the implicit question is: won't this regress headers that are meant to be compatible with earlier standards?
Did the original review mention anything about this?

Clang-tidy already deals with that using the --header-filter option.

Is DAG required because the header file warnings are printed in a different order depending on things like platform?

@njames93 Thank you for review! Yes, on Windows build bot showed different order of the messages so I added -DAG to don't depend on any particular order.

I think the implicit question is: won't this regress headers that are meant to be compatible with earlier standards?
Did the original review mention anything about this?

In the original code review it was not discussed. Moreover it is more or less applicable to all modernize-* checks and they work in headers selected with --header-filter so I think these is no reason to invent special mechanism only for this check.