================ @@ -0,0 +1,121 @@ +// RUN: %check_clang_tidy -std=c++11 %s bugprone-incorrect-enable-shared-from-this %t + +// NOLINTBEGIN +namespace std { + template <typename T> class enable_shared_from_this {}; +} //namespace std +// NOLINTEND + +class BadClassExample : std::enable_shared_from_this<BadClassExample> {}; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: BadClassExample is not publicly inheriting from 'std::enable_shared_from_this', will cause unintended behaviour on 'shared_from_this'. fix this by making it public inheritance [bugprone-incorrect-enable-shared-from-this] +// CHECK-FIXES: public std::enable_shared_from_this<BadClassExample> + +class BadClass2Example : private std::enable_shared_from_this<BadClass2Example> {}; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: BadClass2Example is not publicly inheriting from 'std::enable_shared_from_this', will cause unintended behaviour on 'shared_from_this'. fix this by making it public inheritance [bugprone-incorrect-enable-shared-from-this] +// CHECK-FIXES: public std::enable_shared_from_this<BadClass2Example> + +struct BadStructExample : private std::enable_shared_from_this<BadStructExample> {}; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: BadStructExample is not publicly inheriting from 'std::enable_shared_from_this', will cause unintended behaviour on 'shared_from_this'. fix this by making it public inheritance [bugprone-incorrect-enable-shared-from-this] +// CHECK-FIXES: public std::enable_shared_from_this<BadStructExample> + +class GoodClassExample : public std::enable_shared_from_this<GoodClassExample> {}; + +struct GoodStructExample : public std::enable_shared_from_this<GoodStructExample> {}; + +struct GoodStruct2Example : std::enable_shared_from_this<GoodStruct2Example> {}; + +class dummy_class1 {}; +class dummy_class2 {}; + +class BadMultiClassExample : std::enable_shared_from_this<BadMultiClassExample>, dummy_class1 {}; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: BadMultiClassExample is not publicly inheriting from 'std::enable_shared_from_this', will cause unintended behaviour on 'shared_from_this'. fix this by making it public inheritance [bugprone-incorrect-enable-shared-from-this] ---------------- 5chmidti wrote:
The wording of this diagnostic case can be improved: Either > 'std::enable_shared_from_this', which will cause unintended or > 'BadMultiClassExample' not publicly inheriting https://github.com/llvm/llvm-project/pull/102299 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits