=?utf-8?q?Donát?= Nagy <donat.n...@ericsson.com>, =?utf-8?q?Donát?= Nagy <donat.n...@ericsson.com>, =?utf-8?q?Donát?= Nagy <donat.n...@ericsson.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/130...@github.com>
================ @@ -190,23 +203,38 @@ class CheckerManager { // Checker registration. //===--------------------------------------------------------------------===// - /// Used to register checkers. - /// All arguments are automatically passed through to the checker - /// constructor. + /// Construct the singleton instance of a checker, register it for the + /// supported callbacks and record its name with `registerCheckerPart()`. + /// Arguments passed to this function are forwarded to the constructor of the + /// checker. + /// + /// If `CHECKER` has multiple parts, then the constructor call and the + /// callback registration only happen within the first `registerChecker()` + /// call; while the subsequent calls only enable additional parts of the + /// existing checker object (while registering their names). /// /// \returns a pointer to the checker object. - template <typename CHECKER, typename... AT> - CHECKER *registerChecker(AT &&... Args) { + template <typename CHECKER, CheckerPartIdx Idx = DefaultPart, typename... AT> + CHECKER *registerChecker(AT &&...Args) { + // This assert could be removed but then need to make sure that calls that + // register different parts of the same checker pass the same arguments. + static_assert( + Idx == DefaultPart || !sizeof...(AT), + "Argument forwarding isn't supported with multi-part checkers!"); + CheckerTag Tag = getTag<CHECKER>(); - std::unique_ptr<CheckerBase> &Ref = CheckerTags[Tag]; - assert(!Ref && "Checker already registered, use getChecker!"); - std::unique_ptr<CHECKER> Checker = - std::make_unique<CHECKER>(std::forward<AT>(Args)...); - Checker->Name = CurrentCheckerName; - CHECKER::_register(Checker.get(), *this); - Ref = std::move(Checker); - return static_cast<CHECKER *>(Ref.get()); + std::unique_ptr<CheckerBase> &Ref = CheckerTags[Tag]; + if (!Ref) { + std::unique_ptr<CHECKER> Checker = + std::make_unique<CHECKER>(std::forward<AT>(Args)...); + CHECKER::_register(Checker.get(), *this); + Ref = std::move(Checker); ---------------- steakhal wrote: Can we simplify this into: ```suggestion Ref = std::make_unique<CHECKER>(std::forward<AT>(Args)...); CHECKER::_register(Ref.get(), *this); ``` https://github.com/llvm/llvm-project/pull/130985 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits