Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -232,7 +232,7 @@ public: /// \brief Takes ownership of the provided implementation pointer. explicit Matcher(MatcherInterface *Implementation) - : Implementation(Implementation) {} + : Implementation(Implementation), ImplRefCount(Implementation) {} /// \brief Implicitly converts \c Other to a Matcher. /// @@ -241,17 +241,18 @@ Matcher(const Matcher &Other, typename std::enable_if::value && !std::is_same::value>::type * = 0) - : Implementation(new ImplicitCastMatcher(Other)) {} + : Implementation(new ImplicitCastMatcher(Other)), + ImplRefCount(Implementation) {} /// \brief Implicitly converts \c Matcher to \c Matcher. /// /// The resulting matcher is not strict, i.e. ignores qualifiers. template Matcher(const Matcher &Other, - typename std::enable_if< - std::is_same::value && - std::is_same::value>::type* = 0) - : Implementation(new TypeToQualType(Other)) {} + typename std::enable_if::value && + std::is_same::value>::type * = 0) + : Implementation(new TypeToQualType(Other)), + ImplRefCount(Implementation) {} /// \brief Forwards the call to the underlying MatcherInterface pointer. bool matches(const T &Node, @@ -270,7 +271,7 @@ uint64_t getID() const { /// FIXME: Document the requirements this imposes on matcher /// implementations (no new() implementation_ during a Matches()). - return reinterpret_cast(Implementation.get()); + return reinterpret_cast(Implementation); } /// \brief Allows the conversion of a \c Matcher to a \c @@ -313,7 +314,10 @@ const Matcher From; }; - IntrusiveRefCntPtr< MatcherInterface > Implementation; + MatcherInterface *Implementation; + // Do not instantiate IntrusiveRefCntPtr<> for each MatcherInterface. + // This reduces the symbol bloat that breaks MSVC builds. + IntrusiveRefCntPtr ImplRefCount; }; // class Matcher /// \brief A convenient helper for creating a Matcher without specifying Index: include/clang/ASTMatchers/Dynamic/VariantValue.h =================================================================== --- include/clang/ASTMatchers/Dynamic/VariantValue.h +++ include/clang/ASTMatchers/Dynamic/VariantValue.h @@ -206,6 +206,9 @@ public: typedef ast_matchers::internal::Matcher MatcherT; + TypedMatcherOps() : Out() {} + ~TypedMatcherOps() { delete Out; } + virtual bool canConstructFrom(const DynTypedMatcher &Matcher, bool &IsExactMatch) const { IsExactMatch = Matcher.getSupportedKind().isSame( @@ -214,7 +217,8 @@ } virtual void constructFrom(const DynTypedMatcher& Matcher) { - Out.reset(new MatcherT(Matcher.convertTo())); + delete Out; + Out = new MatcherT(Matcher.convertTo()); } virtual void constructVariadicOperator( @@ -229,16 +233,19 @@ } DynMatchers.push_back(InnerMatchers[i].getTypedMatcher()); } - Out.reset(new MatcherT( + delete Out; + Out = new MatcherT( new ast_matchers::internal::VariadicOperatorMatcherInterface( - Func, DynMatchers))); + Func, DynMatchers)); } - bool hasMatcher() const { return Out.get() != nullptr; } + bool hasMatcher() const { return Out != nullptr; } const MatcherT &matcher() const { return *Out; } private: - std::unique_ptr Out; + // Do not instantiate std::unique_ptr<> for each MatcherT. + // This reduces the symbol bloat that breaks MSVC builds. + MatcherT* Out; }; IntrusiveRefCntPtr Value;