This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Updated language supported restrictions on some checks
Needs RevisionPublic

Authored by njames93 on Mar 3 2020, 9:25 AM.

Diff Detail

Event Timeline

njames93 created this revision.Mar 3 2020, 9:25 AM
alexfh requested changes to this revision.Mar 3 2020, 9:45 AM
alexfh added inline comments.
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
1

IIRC, some of the modernize- checks were meant to be useful to make the pre-C++11 code compile in C++11. This check is an example of this (maybe the only one?). Limiting the check to C++11 and deleting this test is a bit too radical.

This revision now requires changes to proceed.Mar 3 2020, 9:45 AM
njames93 marked an inline comment as done.Mar 3 2020, 12:43 PM
njames93 added inline comments.
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
1

I'm lost, this check is all about replacing assignment of pointer to 0 with nullptr a keyword which doesn't exist pre c++11, so this test case will just result in invalid code. Or am I missing the point?

gribozavr2 added inline comments.Mar 3 2020, 1:04 PM
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
1

The idea, if I understand correctly, is that you start with C++98 code, apply modernize-* checks, and get C++11 code.

alexfh added inline comments.Mar 4 2020, 5:40 AM
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
1

Yep, at least for this particular check there are cases, which won't compile in C++11, but will compile after its fixes are applied. Not sure if this was ever used like this though.

njames93 marked an inline comment as done.Mar 4 2020, 9:25 AM
njames93 added inline comments.
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
1

My understanding of the modernize module was its designed to convert the old c++98/03 code to use newer (safer) c++ constructs. Its purpose isn't to fix compiler errors in c++11 mode that compile OK in c++98 mode

alexfh added inline comments.Mar 5 2020, 4:30 AM
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
1

This and a number of other modernize- checks were migrated from the clang-modernize (previously cpp11-migrate) tool. It's hard to tell now, whether running on code in C++98 mode and fixing errors that would appear in C++11 was a supported use case at the time (though all commits are in git and one could look up, if someone wants to). But that's irrelevant. We need to decide now, whether we want to support this use case or not.
I believe, fixing C++11 compatibility errors in valid C++98 code is a potentially useful feature. Given that it doesn't require additional maintenance costs, I think we should leave it as is. The only downside is complaints from users who blindly run _all_ the checks regardless of whether they need them or not. We could try to relieve this pain, but a better treatment here would be to use the tool correctly, i.e. carefully select the checks to enable. That seems to partly be a UX problem of the frontend they use (CLion in the recent bug report - https://www.jetbrains.com/help/clion/clang-tidy-checks-support.html). Some UIs try to be more user-friendly w.r.t. configuration of the checks (e.g. I found this one today: https://www.cppdepend.com/Modernize).