diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-07-31 09:58:52 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-07-31 09:58:52 +0000 |
commit | 11887924806547ec02e0838644afa80c69084fa8 (patch) | |
tree | 292aaadf9abc3431bfe66a025502152305343d3a /clang-tools-extra/test/clang-tidy/misc-undelegated-constructor.cpp | |
parent | 1cd9e019dae22e01ce608a9b333dfb3e38045d6a (diff) | |
download | bcm5719-llvm-11887924806547ec02e0838644afa80c69084fa8.tar.gz bcm5719-llvm-11887924806547ec02e0838644afa80c69084fa8.zip |
[clang-tidy] Add a checker for code that looks like a delegate constructors but doesn't delegate.
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.
Reviewers: alexfh, djasper
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D4667
llvm-svn: 214397
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-undelegated-constructor.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-undelegated-constructor.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-undelegated-constructor.cpp b/clang-tools-extra/test/clang-tidy/misc-undelegated-constructor.cpp new file mode 100644 index 00000000000..09d683b8e75 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/misc-undelegated-constructor.cpp @@ -0,0 +1,54 @@ +// RUN: clang-tidy -checks='-*,misc-undelegated-constructor' %s -- -std=c++11 2>&1 | FileCheck %s -implicit-check-not='{{warning:|error:}}' + +struct Ctor; +Ctor foo(); + +struct Ctor { + Ctor(); + Ctor(int); + Ctor(int, int); + Ctor(Ctor *i) { + Ctor(); +// CHECK: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead + Ctor(0); +// CHECK: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead + Ctor(1, 2); +// CHECK: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead + foo(); + } +}; + +Ctor::Ctor() { + Ctor(1); +// CHECK: :[[@LINE-1]]:3: warning: did you intend to call a delegated constructor? A temporary object is created here instead +} + +Ctor::Ctor(int i) : Ctor(i, 1) {} // properly delegated. + +struct Dtor { + Dtor(); + Dtor(int); + Dtor(int, int); + Dtor(Ctor *i) { + Dtor(); +// CHECK: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead + Dtor(0); +// CHECK: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead + Dtor(1, 2); +// CHECK: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead + } + ~Dtor(); +}; + +struct Base {}; +struct Derived : public Base { + Derived() { Base(); } +// CHECK: :[[@LINE-1]]:15: warning: did you intend to call a delegated constructor? A temporary object is created here instead +}; + +template <typename T> +struct TDerived : public Base { + TDerived() { Base(); } +}; + +TDerived<int> t; |