This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix PR26274
ClosedPublic

Authored by alexfh on Dec 3 2019, 11:35 AM.

Diff Detail

Event Timeline

alexfh created this revision.Dec 3 2019, 11:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2019, 11:35 AM
Herald added a subscriber: xazax.hun. · View Herald Transcript

Build result: pass - 60438 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt, CMakeCache.txt

Thank you for working on this!

clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
90–92

accross -> across

124

Will this work okay with inline namespaces, or namespaces with attributes written on them? May want test cases for those situations.

gribozavr2 added a subscriber: gribozavr2.

I'm not convinced this feature is worth implementing at all, because there's a good alternative to a macro here -- a namespace alias. What is the reason to use a macro instead of a namespace alias?

I'm not convinced this feature is worth implementing at all, because there's a good alternative to a macro here -- a namespace alias. What is the reason to use a macro instead of a namespace alias?

While I think that's a superior solution to using macros, some users have macros instead. This fixes a bug reported in https://bugs.llvm.org/show_bug.cgi?id=26274 and I agree that the behavior described in that bug is not what I would expect it to be.

gribozavr2 accepted this revision.Dec 4 2019, 7:52 AM

I'm not convinced this feature is worth implementing at all, because there's a good alternative to a macro here -- a namespace alias. What is the reason to use a macro instead of a namespace alias?

While I think that's a superior solution to using macros, some users have macros instead. This fixes a bug reported in https://bugs.llvm.org/show_bug.cgi?id=26274 and I agree that the behavior described in that bug is not what I would expect it to be.

I mean, it is possible to break pretty much any ClangTidy check with sneaky code. But there's a limit to which we should try to make things work in tricky corner cases. For example, the fix in this patch does not handle function-like macros (namespace MY_LIBRARY_NAMESPACE_FOR_VERSION(42) {).

LGTM if we must... but I don't think we should.

This revision is now accepted and ready to land.Dec 4 2019, 7:52 AM
alexfh updated this revision to Diff 232140.Dec 4 2019, 8:12 AM
alexfh marked an inline comment as done.
  • Added support for inline namespaces and namespace attributes, fixed a typo, added tests.
alexfh marked an inline comment as done.Dec 4 2019, 8:14 AM

Build result: pass - 60438 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt, CMakeCache.txt

alexfh added a comment.Dec 4 2019, 9:27 AM

I'm not convinced this feature is worth implementing at all, because there's a good alternative to a macro here -- a namespace alias. What is the reason to use a macro instead of a namespace alias?

While I think that's a superior solution to using macros, some users have macros instead. This fixes a bug reported in https://bugs.llvm.org/show_bug.cgi?id=26274 and I agree that the behavior described in that bug is not what I would expect it to be.

I mean, it is possible to break pretty much any ClangTidy check with sneaky code. But there's a limit to which we should try to make things work in tricky corner cases. For example, the fix in this patch does not handle function-like macros (namespace MY_LIBRARY_NAMESPACE_FOR_VERSION(42) {).

LGTM if we must... but I don't think we should.

Apart from preprocessor-related stuff, this patch improves support for nested inline namespace declarations (namespace a::inline b::c), attributes on namespaces and comments inside namespace declarations. And also reduces the number of special cases. It should be a net positive effect ;)

gribozavr2 accepted this revision.Dec 4 2019, 10:55 AM
gribozavr2 added inline comments.
clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
54

s/begin/beginning/

aaron.ballman added inline comments.Dec 4 2019, 11:15 AM
clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
79

How well do these test cases work?

namespace [[]] {
}

namespace frobble::inline bar {
}

I'm not certain what we want the comment to be for the second example, and I'm not certain the first example will parse properly here.

alexfh updated this revision to Diff 232294.Dec 5 2019, 3:12 AM
alexfh marked 2 inline comments as done.
  • Added a test with an empty attribute list.
alexfh added inline comments.Dec 5 2019, 3:13 AM
clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
79

Both work correctly, in the second case the inline is dropped (why would we want it not to?). See clang-tools-extra/test/clang-tidy/checkers/google-readability-namespace-comments.cpp:66 and clang-tools-extra/test/clang-tidy/checkers/google-readability-namespace-comments-c++17.cpp:4 for tests covering very similar cases. Just in case, I've added a test with an empty attribute list.

Build result: pass - 60438 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt, CMakeCache.txt

aaron.ballman accepted this revision.Dec 5 2019, 4:54 AM

LGTM, thanks for the fixes!

This revision was automatically updated to reflect the committed changes.