[PATCH] D33430: [clang-tidy] Do not dereference a null BaseType

Chih-Hung Hsieh via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 19:33:15 PDT 2017


chh created this revision.
Herald added a subscriber: xazax.hun.

Check BaseType before dereference.
Simplified test case is derived from Android Open Source code.


https://reviews.llvm.org/D33430

Files:
  clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
  test/clang-tidy/misc-forwarding-reference-overload.cpp


Index: test/clang-tidy/misc-forwarding-reference-overload.cpp
===================================================================
--- test/clang-tidy/misc-forwarding-reference-overload.cpp
+++ test/clang-tidy/misc-forwarding-reference-overload.cpp
@@ -121,3 +121,25 @@
 private:
   Test6(const Test6 &rhs);
 };
+
+// Do not dereference a null BaseType.
+template <class _Callable> class result_of;
+template <class _Fp, class ..._Args> class result_of<_Fp(_Args...)> { };
+template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
+
+template <class... _Types> struct __overload;
+template <class _Tp, class... _Types>
+struct __overload<_Tp, _Types...> : __overload<_Types...> {
+  using __overload<_Types...>::operator();
+};
+
+template <class _Tp, class... _Types>
+using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type;
+
+template <class... _Types>
+class variant {
+public:
+  template <class _Arg, class _Tp = __best_match_t<_Arg, _Types...> >
+  constexpr variant(_Arg&& __arg) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors
+};
Index: clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
===================================================================
--- clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
+++ clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
@@ -40,6 +40,8 @@
   if (const auto *Dependent = BaseType->getAs<DependentNameType>()) {
     BaseType = Dependent->getQualifier()->getAsType();
   }
+  if (!BaseType)
+    return false;
   if (CheckTemplate(BaseType->getAs<TemplateSpecializationType>())) {
     return true; // Case: enable_if_t< >.
   } else if (const auto *Elaborated = BaseType->getAs<ElaboratedType>()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33430.99842.patch
Type: text/x-patch
Size: 1786 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170523/5cbd431e/attachment-0001.bin>


More information about the cfe-commits mailing list