This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add a checker for code that looks like a delegate constructors but doesn't delegate.
ClosedPublic

Authored by bkramer on Jul 25 2014, 8:22 AM.

Details

Summary

class Foo {

Foo() {
  Foo(42); // oops
}
Foo(int);

};

This is valid code but it does nothing and we can't emit a warning in clang
because there might be side effects. The checker emits a warning for this
pattern and also for base class initializers written in this style.

There is some overlap with the unused-rtti checker but they follow different
goals and fire in different places most of the time.

Diff Detail

Repository
rL LLVM

Event Timeline

bkramer updated this revision to Diff 11880.Jul 25 2014, 8:22 AM
bkramer retitled this revision from to [clang-tidy] Add a checker for code that looks like a delegate constructors but doesn't delegate..
bkramer updated this object.
bkramer added reviewers: alexfh, djasper.
bkramer added a subscriber: Unknown Object (MLST).
alexfh accepted this revision.Jul 29 2014, 7:45 AM
alexfh edited edge metadata.
alexfh added inline comments.
clang-tidy/misc/CMakeLists.txt
9 ↗(On Diff #11880)

I'd add "Check" to the class name for consistency.

clang-tidy/misc/UndelegatedConstructor.cpp
63 ↗(On Diff #11880)

Please add a test with template instantiations. It's useful to know that the matcher doesn't crash on them ;)

72 ↗(On Diff #11880)

The message could be a bit clearer of what actually happens here. Maybe something along the lines of: "Did you intend to call a delegated constructor? A temporary object is created here instead"

test/clang-tidy/misc-undelegated-constructor.cpp
1 ↗(On Diff #11880)

Please add -implicit-check-not='{{warning:|error:}}'.

This revision is now accepted and ready to land.Jul 29 2014, 7:45 AM
bkramer closed this revision.Jul 31 2014, 3:07 AM
bkramer updated this revision to Diff 12060.

Closed by commit rL214397 (authored by d0k).