This is an archive of the discontinued LLVM Phabricator instance.

[Clang-tidy] Make null pointer literals for fixes configurable for two checks
AbandonedPublic

Authored by Eugene.Zelenko on Jan 28 2016, 5:16 PM.

Details

Summary

This is fix for PR26295. I added configuration option to readability-implicit-bool-cast and readability-simplify-boolean-expr.

Build and regressions were OK on RHEL6.

I think one global option will better then per-check ones, but I'm not aware of examples.

Diff Detail

Repository
rL LLVM

Event Timeline

Eugene.Zelenko retitled this revision from to [Clang-tidy] Make null pointer literals for fixes configurable for two checks.
Eugene.Zelenko updated this object.
Eugene.Zelenko set the repository for this revision to rL LLVM.
Eugene.Zelenko added a subscriber: cfe-commits.
aaron.ballman edited edge metadata.Feb 2 2016, 5:48 AM

Missing test cases.

As for a global option, once D16113 lands, you can use getLocalOrGlobal() if you want to use a global option for this functionality.

clang-tidy/readability/ImplicitBoolCastCheck.cpp
69

Check can be a const pointer.

126

Same here.

clang-tidy/readability/ImplicitBoolCastCheck.h
32

I know you are following the pattern used in the code here, but I think this class needs a storeOptions() function as well. See AssertSideEffectCheck as an example.

clang-tidy/readability/SimplifyBooleanExprCheck.cpp
175

Check can be a const pointer.

276

I think this also needs a storeOptions() method.

Eugene.Zelenko abandoned this revision.Feb 2 2016, 10:49 AM

I'll wait for global options implementation.

clang-tidy/readability/ImplicitBoolCastCheck.h
32

This will need rebasing on the existing code, which is using "NULL" as the pre-C++11 fallback default, not "0".

36–38

I don't understand why the checks need a public getter for the nullptr literal being used.

clang-tidy/readability/SimplifyBooleanExprCheck.cpp
175

Passing the check in here is overkill. This helper function isn't going to ever be used for multiple checks and the only thing you ever do with the check is get the nullptr literal, so just pass in the thing it needs directly.

This will also need to be rebased onto the current code.

docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
79–81

The wording here is awkward. Instead, I suggest:

The option ``NullPointerLiteral`` configures the text used for comparisons of pointers
against zero to synthesize boolean expressions.  The default value for C++11 or later
is ``nullptr``, otherwise the value is ``NULL``.

It's subjective, but my experience is that pre C++11 code bases prefer NULL over 0.

Eugene.Zelenko added inline comments.Feb 3 2016, 4:33 PM
clang-tidy/readability/ImplicitBoolCastCheck.h
32

This was in original code. I just didn't want to change default.

clang-tidy/readability/SimplifyBooleanExprCheck.cpp
175

I had same idea, but I'm waiting for global options implementation to make other changes,

docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
79–81

English is not my native language, so help is welcomed.

aaron.ballman added inline comments.Feb 4 2016, 5:42 AM
clang-tidy/readability/ImplicitBoolCastCheck.h
32

If the code is using NULL as the pre-C++11 fallback, don't we also need an include for stddef.h/cstddef?

36–38

Agreed, good catch.

alexfh edited edge metadata.Feb 4 2016, 6:48 AM

Please include full context to the diffs. See http://llvm.org/docs/Phabricator.html for instructions.