Author: chh Date: Tue May 23 11:19:04 2017 New Revision: 303645 URL: http://llvm.org/viewvc/llvm-project?rev=303645&view=rev Log: [clang-tidy] Do not dereference a null BaseType
Check BaseType before dereference. Simplified test case is derived from Android Open Source code. Differential Revision: https://reviews.llvm.org/D33430 Modified: clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp?rev=303645&r1=303644&r2=303645&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp Tue May 23 11:19:04 2017 @@ -40,6 +40,8 @@ AST_MATCHER(QualType, isEnableIf) { 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>()) { Modified: clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp?rev=303645&r1=303644&r2=303645&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp Tue May 23 11:19:04 2017 @@ -121,3 +121,25 @@ public: 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 +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits