This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`
AbandonedPublic

Authored by v1nh1shungry on Jan 15 2023, 3:34 AM.

Details

Summary

Currently this check will complain when there're preprocessor directives
like macro definitions between the namespaces, e.g.

namespace a { // warns, but it shouldn't
 #define FOO
namespace b {
} // namespace b
} // namespace a

Fixes https://github.com/llvm/llvm-project/issues/60035 partly

Diff Detail

Event Timeline

v1nh1shungry created this revision.Jan 15 2023, 3:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: xazax.hun. · View Herald Transcript
v1nh1shungry requested review of this revision.Jan 15 2023, 3:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2023, 3:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
v1nh1shungry planned changes to this revision.Jan 15 2023, 4:30 AM

This patch doesn't handle situations like:

namespace a {
namespace b {
#define FOO
namespace c {
}
}
}

This patch doesn't handle situations like:

namespace a {
namespace b {
#define FOO
namespace c {
}
}
}

It did. I must be mad :(

gribozavr2 accepted this revision.Jan 15 2023, 8:07 AM
This revision is now accepted and ready to land.Jan 15 2023, 8:07 AM
njames93 requested changes to this revision.Jan 15 2023, 2:14 PM
njames93 added inline comments.
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
173

Is CHECK-MESSAGES-DAG needed here, why does it fail if this is omitted?

This revision now requires changes to proceed.Jan 15 2023, 2:14 PM
v1nh1shungry added inline comments.Jan 15 2023, 6:57 PM
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
173

Hmm, doesn't CHECK-MESSAGES-DAG means to check whether there is a message? (I referred to the tests above.)

If it's other cases, maybe it's due to https://github.com/llvm/llvm-project/issues/60051.

I'm not sure I understand what you mean, sorry!

Ping? @njames93

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

Hmm, doesn't CHECK-MESSAGES-DAG means to check whether there is a message? (I referred to the tests above.)

If it's other cases, maybe it's due to https://github.com/llvm/llvm-project/issues/60051.

I'm not sure I understand what you mean, sorry!

I think I understand now. You mean the whole test doesn't fail even without this CHECK-MESSAGES-DAG, right?

If so, this CHECK-MESSAGES-DAG is needed. I think the reason that the test doesn't fail without it is https://github.com/llvm/llvm-project/issues/60051. The check isn't applied correctly before I make any code changes, you can have a play with https://godbolt.org/z/nc34shM8W. But I think the problem isn't related to the check itself because when I apply this check through clangd's code action it produces correct codes as I mentioned in the GitHub issue.

LegalizeAdulthood resigned from this revision.Mar 29 2023, 8:06 AM
v1nh1shungry abandoned this revision.Apr 8 2023, 8:16 PM