This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.
ClosedPublic

Authored by etienneb on Apr 26 2016, 11:29 AM.

Details

Summary

Arguments can be swapped using fixit when they are not in macros.
This is the same implementation than SwappedArguments. Some code
got lifted to be reused.

Others checks are not safe to be fixed as they tend to be bugs or errors.
It is better to let the user manually review them.

Diff Detail

Event Timeline

etienneb updated this revision to Diff 55053.Apr 26 2016, 11:29 AM
etienneb retitled this revision from to [clang-tidy] Add FixIt for swapping arguments in string-constructor-checker..
etienneb updated this object.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.
alexfh requested changes to this revision.Apr 27 2016, 4:29 AM
alexfh edited edge metadata.
alexfh added inline comments.
clang-tidy/misc/StringConstructorCheck.cpp
110–115

Assertions should verify logical bugs in the code, not some properties of the user input. The matcher doesn't seem to ensure that the argument count is always 2, so it's possible to create code that will trigger this assertion. Either add argumentCountIs(2) to the matcher or remove the assertion.

This revision now requires changes to proceed.Apr 27 2016, 4:29 AM
etienneb updated this revision to Diff 55242.Apr 27 2016, 8:44 AM
etienneb edited edge metadata.

address alexfh comments.

clang-tidy/misc/StringConstructorCheck.cpp
110–115

As I get it, it's not needed to add ' argumentCountIs(2)' because:

hasArgument(0, hasType(CharPtrType)),
hasArgument(1, hasType(isInteger())),

the code already validates that there is at least two parameters.
The assert would fail if there is more parameters, which can occur only on a incorrect definition of the constructor.

So, I'm i favor to just remove the assert.

alexfh requested changes to this revision.Apr 29 2016, 9:14 AM
alexfh edited edge metadata.
alexfh added inline comments.
clang-tidy/misc/StringConstructorCheck.cpp
110–115

We could make the message slightly more specific by saying it's std::(basic_)?string constructor.

115

You should be able to use Lexer::getSourceText instead.

This revision now requires changes to proceed.Apr 29 2016, 9:14 AM
etienneb updated this revision to Diff 56919.May 11 2016, 8:42 AM
etienneb edited edge metadata.
etienneb marked an inline comment as done.

use new API. code simplification

alexfh accepted this revision.May 11 2016, 10:16 AM
alexfh edited edge metadata.

LG.

This revision is now accepted and ready to land.May 11 2016, 10:16 AM
etienneb closed this revision.May 11 2016, 10:38 AM