diff --git a/.clang-tidy b/.clang-tidy index 9a09c33933a..46642f86420 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,4 @@ -Checks: '-*,modernize-make-shared,performance-*,-performance-inefficient-string-concatenation,readability-const-return-type,readability-container-size-empty,misc-definitions-in-headers,modernize-use-override' +Checks: '-*,modernize-make-shared,performance-*,-performance-inefficient-string-concatenation,readability-const-return-type,readability-container-size-empty,misc-definitions-in-headers,modernize-use-override,google-explicit-constructor,hicpp-explicit-conversions' WarningsAsErrors: '*' CheckOptions: - key: modernize-use-override.IgnoreDestructors diff --git a/libredex/ApkManager.h b/libredex/ApkManager.h index a1dbec69466..74cbc65892a 100644 --- a/libredex/ApkManager.h +++ b/libredex/ApkManager.h @@ -13,7 +13,7 @@ class ApkManager { public: - ApkManager(std::string&& apk_dir) : m_apk_dir(apk_dir) {} + explicit ApkManager(std::string&& apk_dir) : m_apk_dir(apk_dir) {} virtual ~ApkManager() { for (auto& fd : m_files) { diff --git a/libredex/CFGMutation.h b/libredex/CFGMutation.h index 92c10f4b381..40e1e5758d2 100644 --- a/libredex/CFGMutation.h +++ b/libredex/CFGMutation.h @@ -24,7 +24,7 @@ namespace cfg { class CFGMutation { public: /// Create a new mutation to apply to \p cfg. - CFGMutation(ControlFlowGraph& cfg); + explicit CFGMutation(ControlFlowGraph& cfg); /// CFGMutation is not copyable CFGMutation(const CFGMutation&) = delete; diff --git a/libredex/CallGraph.cpp b/libredex/CallGraph.cpp index 7b1515b8c5c..bee520ee1f9 100644 --- a/libredex/CallGraph.cpp +++ b/libredex/CallGraph.cpp @@ -18,7 +18,7 @@ using namespace call_graph; class SingleCalleeStrategy final : public BuildStrategy { public: - SingleCalleeStrategy(const Scope& scope) : m_scope(scope) { + explicit SingleCalleeStrategy(const Scope& scope) : m_scope(scope) { auto non_virtual_vec = mog::get_non_true_virtuals(scope); m_non_virtual.insert(non_virtual_vec.begin(), non_virtual_vec.end()); } diff --git a/libredex/CallGraph.h b/libredex/CallGraph.h index 29ab37c8345..713911d67d5 100644 --- a/libredex/CallGraph.h +++ b/libredex/CallGraph.h @@ -112,7 +112,7 @@ class Edge { class Graph final { public: - Graph(const BuildStrategy&); + explicit Graph(const BuildStrategy&); NodeId entry() const { return m_entry; } NodeId exit() const { return m_exit; } diff --git a/libredex/ConcurrentContainers.h b/libredex/ConcurrentContainers.h index 7b692ac968b..2328e2eebe5 100644 --- a/libredex/ConcurrentContainers.h +++ b/libredex/ConcurrentContainers.h @@ -380,10 +380,13 @@ class ConcurrentContainerIterator final { using base_iterator = std::conditional_t::value, typename Container::const_iterator, typename Container::iterator>; + using const_base_iterator = typename Container::const_iterator; using difference_type = std::ptrdiff_t; using value_type = typename base_iterator::value_type; using pointer = typename base_iterator::pointer; + using const_pointer = typename Container::const_iterator::pointer; using reference = typename base_iterator::reference; + using const_reference = typename Container::const_iterator::reference; using iterator_category = std::forward_iterator_tag; explicit ConcurrentContainerIterator(Container* slots) @@ -432,12 +435,12 @@ class ConcurrentContainerIterator final { return m_position.operator->(); } - const reference operator*() const { + const_reference operator*() const { always_assert(m_position != m_slots[n_slots - 1].end()); return *m_position; } - const pointer operator->() const { + const_pointer operator->() const { always_assert(m_position != m_slots[n_slots - 1].end()); return m_position.operator->(); } diff --git a/libredex/ConfigFiles.h b/libredex/ConfigFiles.h index e5c5a61e4d3..c928739e798 100644 --- a/libredex/ConfigFiles.h +++ b/libredex/ConfigFiles.h @@ -29,7 +29,7 @@ using MethodMap = std::map; * ConfigFiles should be a readonly structure */ struct ConfigFiles { - ConfigFiles(const Json::Value& config); + explicit ConfigFiles(const Json::Value& config); ConfigFiles(const Json::Value& config, const std::string& outdir); const std::vector& get_coldstart_classes() { diff --git a/libredex/Creators.h b/libredex/Creators.h index 1f4cb4b5c4c..63731c54591 100644 --- a/libredex/Creators.h +++ b/libredex/Creators.h @@ -384,7 +384,7 @@ struct MethodBlock { */ struct MethodCreator { public: - MethodCreator(DexMethod* meth); + explicit MethodCreator(DexMethod* meth); MethodCreator(DexMethodRef* ref, DexAccessFlags access, DexAnnotationSet* anno = nullptr, diff --git a/libredex/DexAnnotation.h b/libredex/DexAnnotation.h index 49b35d5014f..7dcf0a8ee36 100644 --- a/libredex/DexAnnotation.h +++ b/libredex/DexAnnotation.h @@ -60,7 +60,7 @@ class DexEncodedValue : public Gatherable { DexEncodedValueTypes m_evtype; uint64_t m_value; - DexEncodedValue(DexEncodedValueTypes type, uint64_t value = 0) + explicit DexEncodedValue(DexEncodedValueTypes type, uint64_t value = 0) : Gatherable() { m_evtype = type; m_value = value; @@ -110,7 +110,8 @@ class DexEncodedValueString : public DexEncodedValue { DexString* m_string; public: - DexEncodedValueString(DexString* string) : DexEncodedValue(DEVT_STRING) { + explicit DexEncodedValueString(DexString* string) + : DexEncodedValue(DEVT_STRING) { m_string = string; } @@ -138,7 +139,7 @@ class DexEncodedValueType : public DexEncodedValue { DexType* m_type; public: - DexEncodedValueType(DexType* type) : DexEncodedValue(DEVT_TYPE) { + explicit DexEncodedValueType(DexType* type) : DexEncodedValue(DEVT_TYPE) { m_type = type; } @@ -196,7 +197,8 @@ class DexEncodedValueMethod : public DexEncodedValue { DexMethodRef* m_method; public: - DexEncodedValueMethod(DexMethodRef* method) : DexEncodedValue(DEVT_METHOD) { + explicit DexEncodedValueMethod(DexMethodRef* method) + : DexEncodedValue(DEVT_METHOD) { m_method = method; } @@ -303,8 +305,8 @@ class DexEncodedValueArray : public DexEncodedValue { * Static values are encoded without a DEVT_ARRAY header byte * so we differentiate that here. */ - DexEncodedValueArray(std::deque* evalues, - bool static_val = false) + explicit DexEncodedValueArray(std::deque* evalues, + bool static_val = false) : DexEncodedValue(DEVT_ARRAY), m_evalues(evalues) { m_static_val = static_val; } diff --git a/libredex/DexClass.h b/libredex/DexClass.h index 05ec089164a..0f1af3dbe23 100644 --- a/libredex/DexClass.h +++ b/libredex/DexClass.h @@ -184,7 +184,7 @@ class DexType { DexString* m_name; // See UNIQUENESS above for the rationale for the private constructor pattern. - DexType(DexString* dstring) { m_name = dstring; } + explicit DexType(DexString* dstring) { m_name = dstring; } public: // DexType retrieval/creation @@ -474,7 +474,7 @@ class DexTypeList { std::deque m_list; // See UNIQUENESS above for the rationale for the private constructor pattern. - DexTypeList(std::deque&& p) { m_list = std::move(p); } + explicit DexTypeList(std::deque&& p) { m_list = std::move(p); } public: std::deque::iterator begin() { return m_list.begin(); } @@ -1118,7 +1118,7 @@ class DexClass { std::vector m_dmethods; std::vector m_vmethods; - DexClass(const std::string& location) : m_location(location){}; + explicit DexClass(const std::string& location) : m_location(location){}; void load_class_annotations(DexIdx* idx, uint32_t anno_off); void load_class_data_item(DexIdx* idx, uint32_t cdi_off, diff --git a/libredex/DexDebugInstruction.h b/libredex/DexDebugInstruction.h index 461f9b971fc..3d5b38d0b6d 100644 --- a/libredex/DexDebugInstruction.h +++ b/libredex/DexDebugInstruction.h @@ -30,7 +30,7 @@ class DexDebugInstruction : public Gatherable { DexDebugItemOpcode m_opcode; public: - DexDebugInstruction(DexDebugItemOpcode op, uint32_t v = DEX_NO_INDEX) + explicit DexDebugInstruction(DexDebugItemOpcode op, uint32_t v = DEX_NO_INDEX) : Gatherable() { m_opcode = op; m_uvalue = v; @@ -77,7 +77,8 @@ class DexDebugOpcodeSetFile : public DexDebugInstruction { DexString* m_str; public: - DexDebugOpcodeSetFile(DexString* str) : DexDebugInstruction(DBG_SET_FILE) { + explicit DexDebugOpcodeSetFile(DexString* str) + : DexDebugInstruction(DBG_SET_FILE) { m_str = str; } diff --git a/libredex/DexHasher.h b/libredex/DexHasher.h index 577a670ff07..5dcb06aea61 100644 --- a/libredex/DexHasher.h +++ b/libredex/DexHasher.h @@ -37,7 +37,7 @@ struct DexHash { class DexScopeHasher final { public: - DexScopeHasher(const Scope& scope) : m_scope(scope) {} + explicit DexScopeHasher(const Scope& scope) : m_scope(scope) {} DexHash run(); private: @@ -46,7 +46,7 @@ class DexScopeHasher final { class DexClassHasher final { public: - DexClassHasher(DexClass* cls) : m_cls(cls) {} + explicit DexClassHasher(DexClass* cls) : m_cls(cls) {} DexHash run(); private: diff --git a/libredex/DexInstruction.h b/libredex/DexInstruction.h index 4bbe35306b9..9830f42d9c2 100644 --- a/libredex/DexInstruction.h +++ b/libredex/DexInstruction.h @@ -65,7 +65,7 @@ class DexInstruction : public Gatherable { } public: - DexInstruction(DexOpcode op) + explicit DexInstruction(DexOpcode op) : Gatherable(), m_opcode(op), m_count(count_from_opcode()) {} DexInstruction(DexOpcode opcode, uint16_t arg) : DexInstruction(opcode) { @@ -313,7 +313,7 @@ class DexOpcodeData : public DexInstruction { memcpy(m_data, opcodes, count * sizeof(uint16_t)); } - DexOpcodeData(const std::vector& opcodes) + explicit DexOpcodeData(const std::vector& opcodes) : DexInstruction(&opcodes[0], 0), m_data_count(opcodes.size() - 1), m_data(new uint16_t[opcodes.size() - 1]) { diff --git a/libredex/DexOutput.h b/libredex/DexOutput.h index 192f116ab59..d0a08904023 100644 --- a/libredex/DexOutput.h +++ b/libredex/DexOutput.h @@ -240,8 +240,8 @@ class GatheredTypes { void build_method_map(); public: - GatheredTypes(DexClasses* classes, - PostLowering const* post_lowering = nullptr); + explicit GatheredTypes(DexClasses* classes, + PostLowering const* post_lowering = nullptr); DexOutputIdx* get_dodx(const uint8_t* base); template diff --git a/libredex/DexPosition.h b/libredex/DexPosition.h index 3d125eb2203..b905a3d59e1 100644 --- a/libredex/DexPosition.h +++ b/libredex/DexPosition.h @@ -24,7 +24,7 @@ struct DexPosition final { // when a function gets inlined for the first time, all its DexPositions will // have the DexPosition of the callsite as their parent. DexPosition* parent{nullptr}; - DexPosition(uint32_t line); + explicit DexPosition(uint32_t line); DexPosition(DexString* method, DexString* file, uint32_t line); void bind(DexString* method_, DexString* file_); @@ -58,7 +58,7 @@ class RealPositionMapper : public PositionMapper { void write_map_v2(); public: - RealPositionMapper(const std::string& filename_v2) + explicit RealPositionMapper(const std::string& filename_v2) : m_filename_v2(filename_v2) {} DexString* get_source_file(const DexClass*) override; uint32_t position_to_line(DexPosition*) override; diff --git a/libredex/DexStore.h b/libredex/DexStore.h index 9552d449a44..952d184e3c8 100644 --- a/libredex/DexStore.h +++ b/libredex/DexStore.h @@ -43,8 +43,8 @@ class DexStore { bool m_generated = false; public: - DexStore(const DexMetadata& metadata) : m_metadata(metadata){}; - DexStore(const std::string& name); + explicit DexStore(const DexMetadata& metadata) : m_metadata(metadata){}; + explicit DexStore(const std::string& name); std::string get_name() const; const std::string& get_dex_magic() const { return dex_magic; } @@ -74,12 +74,12 @@ class DexStoreClassesIterator classes_iterator m_current_classes; public: - DexStoreClassesIterator(std::vector& stores) + explicit DexStoreClassesIterator(std::vector& stores) : m_stores(stores), m_current_store(stores.begin()), m_current_classes(m_current_store->get_dexen().begin()) {} - DexStoreClassesIterator(const std::vector& stores) + explicit DexStoreClassesIterator(const std::vector& stores) : m_stores(const_cast&>(stores)), m_current_store(m_stores.begin()), m_current_classes(m_current_store->get_dexen().begin()) {} diff --git a/libredex/DexTypeEnvironment.h b/libredex/DexTypeEnvironment.h index da45ff4cd2f..d38c6d1d457 100644 --- a/libredex/DexTypeEnvironment.h +++ b/libredex/DexTypeEnvironment.h @@ -160,8 +160,7 @@ class DexTypeEnvironment final // insert a redundant '= default'. DexTypeEnvironment() = default; - explicit DexTypeEnvironment( - std::initializer_list> l) + DexTypeEnvironment(std::initializer_list> l) : ReducedProductAbstractDomain( std::make_tuple(RegTypeEnvironment(l), FieldTypeEnvironment())) {} diff --git a/libredex/Dominators.h b/libredex/Dominators.h index 457c7a5c471..8ca22df3e43 100644 --- a/libredex/Dominators.h +++ b/libredex/Dominators.h @@ -23,7 +23,7 @@ class SimpleFastDominators { * * K. D. Cooper et.al. A Simple, Fast Dominance Algorithm. */ - SimpleFastDominators(const typename GraphInterface::Graph& graph) { + explicit SimpleFastDominators(const typename GraphInterface::Graph& graph) { // Sort nodes in postorder and create a map of each node to its postorder // number. m_postordering = graph::postorder_sort(graph); diff --git a/libredex/IRList.h b/libredex/IRList.h index 87f07180bd6..52f4d9ada0b 100644 --- a/libredex/IRList.h +++ b/libredex/IRList.h @@ -38,7 +38,8 @@ struct TryEntry { struct CatchEntry { DexType* catch_type; MethodItemEntry* next; // always null for catchall - CatchEntry(DexType* catch_type) : catch_type(catch_type), next(nullptr) {} + explicit CatchEntry(DexType* catch_type) + : catch_type(catch_type), next(nullptr) {} bool operator==(const CatchEntry& other) const; }; @@ -75,7 +76,7 @@ struct BranchTarget { int32_t case_key; BranchTarget() = default; - BranchTarget(MethodItemEntry* src) : src(src), type(BRANCH_SIMPLE) {} + explicit BranchTarget(MethodItemEntry* src) : src(src), type(BRANCH_SIMPLE) {} BranchTarget(MethodItemEntry* src, int32_t case_key) : src(src), type(BRANCH_MULTI), case_key(case_key) {} @@ -142,15 +143,15 @@ struct MethodItemEntry { } MethodItemEntry(TryEntryType try_type, MethodItemEntry* catch_start) : type(MFLOW_TRY), tentry(new TryEntry(try_type, catch_start)) {} - MethodItemEntry(DexType* catch_type) + explicit MethodItemEntry(DexType* catch_type) : type(MFLOW_CATCH), centry(new CatchEntry(catch_type)) {} - MethodItemEntry(BranchTarget* bt) { + explicit MethodItemEntry(BranchTarget* bt) { this->type = MFLOW_TARGET; this->target = bt; } - MethodItemEntry(std::unique_ptr dbgop) + explicit MethodItemEntry(std::unique_ptr dbgop) : type(MFLOW_DEBUG), dbgop(std::move(dbgop)) {} - MethodItemEntry(std::unique_ptr pos) + explicit MethodItemEntry(std::unique_ptr pos) : type(MFLOW_POSITION), pos(std::move(pos)) {} bool operator==(const MethodItemEntry&) const; diff --git a/libredex/InstructionAnalyzer.h b/libredex/InstructionAnalyzer.h index f6b76d53bc0..87cf6047797 100644 --- a/libredex/InstructionAnalyzer.h +++ b/libredex/InstructionAnalyzer.h @@ -164,7 +164,7 @@ class InstructionAnalyzerCombiner final { "InstructionAnalyzerBase!"); } - InstructionAnalyzerCombiner(typename Analyzers::State... states) + explicit InstructionAnalyzerCombiner(typename Analyzers::State... states) : m_states(std::make_tuple(states...)) {} // If all sub-analyzers have a default-constructible state, then this diff --git a/libredex/KeepReason.h b/libredex/KeepReason.h index e24b2ccac9d..2b48bb83cda 100644 --- a/libredex/KeepReason.h +++ b/libredex/KeepReason.h @@ -44,7 +44,7 @@ struct Reason { const DexMethod* method; }; - Reason(KeepReasonType type) : type(type) { + explicit Reason(KeepReasonType type) : type(type) { always_assert(type != KEEP_RULE && type != REFLECTION); } diff --git a/libredex/MethodDevirtualizer.h b/libredex/MethodDevirtualizer.h index d284b70b7ca..ff7b7541686 100644 --- a/libredex/MethodDevirtualizer.h +++ b/libredex/MethodDevirtualizer.h @@ -15,17 +15,6 @@ struct DevirtualizerConfigs { bool dmethods_not_using_this = true; bool dmethods_using_this = false; bool ignore_keep = false; - - DevirtualizerConfigs(bool vmethods_not_using_this = true, - bool vmethods_using_this = false, - bool dmethods_not_using_this = true, - bool dmethods_using_this = false, - bool ignore_keep = false) - : vmethods_not_using_this(vmethods_not_using_this), - vmethods_using_this(vmethods_using_this), - dmethods_not_using_this(dmethods_not_using_this), - dmethods_using_this(dmethods_using_this), - ignore_keep(ignore_keep) {} }; struct DevirtualizerMetrics { diff --git a/libredex/OptData.h b/libredex/OptData.h index a2268034b9a..7ab19eab2e0 100644 --- a/libredex/OptData.h +++ b/libredex/OptData.h @@ -90,7 +90,7 @@ class MethodOptData { friend class OptDataMapper; public: - MethodOptData(const DexMethod* method); + explicit MethodOptData(const DexMethod* method); std::shared_ptr get_insn_opt_data(const IRInstruction* insn); private: @@ -111,7 +111,7 @@ class ClassOptData { friend class OptDataMapper; public: - ClassOptData(const DexClass* cls); + explicit ClassOptData(const DexClass* cls); std::shared_ptr get_meth_opt_data(const DexMethod* method); private: diff --git a/libredex/Pass.h b/libredex/Pass.h index 936235b9479..d6b9e5e56d3 100644 --- a/libredex/Pass.h +++ b/libredex/Pass.h @@ -24,7 +24,7 @@ class PassManager; class Pass : public Configurable { public: - Pass(const std::string& name) : m_name(name) { + explicit Pass(const std::string& name) : m_name(name) { PassRegistry::get().register_pass(this); } diff --git a/libredex/PassManager.h b/libredex/PassManager.h index 550ca5aa1e7..3c89788c54d 100644 --- a/libredex/PassManager.h +++ b/libredex/PassManager.h @@ -22,9 +22,10 @@ class PassManager { public: - PassManager(const std::vector& passes, - const Json::Value& config = Json::Value(Json::objectValue), - const RedexOptions& options = RedexOptions{}); + explicit PassManager( + const std::vector& passes, + const Json::Value& config = Json::Value(Json::objectValue), + const RedexOptions& options = RedexOptions{}); PassManager(const std::vector& passes, std::unique_ptr pg_config, diff --git a/libredex/PointsToSemantics.h b/libredex/PointsToSemantics.h index 58822e6eba5..b19b8e870c4 100644 --- a/libredex/PointsToSemantics.h +++ b/libredex/PointsToSemantics.h @@ -521,7 +521,7 @@ class PointsToSemantics final { * the flag `generate_stubs` is set to true, all methods in the scope are * interpreted as stubs. */ - PointsToSemantics(const Scope& scope, bool generate_stubs = false); + explicit PointsToSemantics(const Scope& scope, bool generate_stubs = false); /* * The stubs are stored in the specified text file as S-expressions. In case diff --git a/libredex/PriorityThreadPool.h b/libredex/PriorityThreadPool.h index 8a73edd9f05..ea31d32b7b4 100644 --- a/libredex/PriorityThreadPool.h +++ b/libredex/PriorityThreadPool.h @@ -51,7 +51,7 @@ class PriorityThreadPool { } // Creates an instance with a custom number of threads - PriorityThreadPool(int num_threads) { set_num_threads(num_threads); } + explicit PriorityThreadPool(int num_threads) { set_num_threads(num_threads); } ~PriorityThreadPool() { // .join() must be manually called before the executor may be destroyed diff --git a/libredex/ProguardLexer.h b/libredex/ProguardLexer.h index 943a68eea56..2fb7b1aa7f0 100644 --- a/libredex/ProguardLexer.h +++ b/libredex/ProguardLexer.h @@ -137,190 +137,206 @@ class Token { class OpenCurlyBracket : public Token { public: - OpenCurlyBracket(unsigned int line_number) + explicit OpenCurlyBracket(unsigned int line_number) : Token(token::openCurlyBracket, line_number) {} string show() const override { return "{"; } }; class CloseCurlyBracket : public Token { public: - CloseCurlyBracket(unsigned int line_number) + explicit CloseCurlyBracket(unsigned int line_number) : Token(token::closeCurlyBracket, line_number) {} string show() const override { return "}"; } }; class OpenBracket : public Token { public: - OpenBracket(unsigned int line_number) + explicit OpenBracket(unsigned int line_number) : Token(token::openBracket, line_number) {} string show() const override { return "("; } }; class CloseBracket : public Token { public: - CloseBracket(unsigned int line_number) + explicit CloseBracket(unsigned int line_number) : Token(token::closeBracket, line_number) {} string show() const override { return ")"; } }; class SemiColon : public Token { public: - SemiColon(unsigned int line_number) : Token(token::semiColon, line_number) {} + explicit SemiColon(unsigned int line_number) + : Token(token::semiColon, line_number) {} string show() const override { return ";"; } }; class Colon : public Token { public: - Colon(unsigned int line_number) : Token(token::colon, line_number) {} + explicit Colon(unsigned int line_number) : Token(token::colon, line_number) {} string show() const override { return ":"; } }; class Not : public Token { public: - Not(unsigned int line_number) : Token(token::notToken, line_number){}; + explicit Not(unsigned int line_number) + : Token(token::notToken, line_number){}; string show() const override { return "!"; } }; class Comma : public Token { public: - Comma(unsigned int line_number) : Token(token::comma, line_number){}; + explicit Comma(unsigned int line_number) : Token(token::comma, line_number){}; string show() const override { return ","; } }; class Slash : public Token { public: - Slash(unsigned int line_number) : Token(token::slash, line_number){}; + explicit Slash(unsigned int line_number) : Token(token::slash, line_number){}; string show() const override { return "/"; } }; class Annotation : public Token { public: - Annotation(unsigned int line_number) + explicit Annotation(unsigned int line_number) : Token(token::annotation, line_number){}; string show() const override { return "@interface"; } }; class AnnotationApplication : public Token { public: - AnnotationApplication(unsigned int line_number) + explicit AnnotationApplication(unsigned int line_number) : Token(token::annotation_application, line_number){}; string show() const override { return "@"; } }; class Class : public Token { public: - Class(unsigned int line_number) : Token(token::classToken, line_number) {} + explicit Class(unsigned int line_number) + : Token(token::classToken, line_number) {} string show() const override { return "class"; } }; class Public : public Token { public: - Public(unsigned int line_number) : Token(token::publicToken, line_number) {} + explicit Public(unsigned int line_number) + : Token(token::publicToken, line_number) {} string show() const override { return "public"; } }; class Final : public Token { public: - Final(unsigned int line_number) : Token(token::final, line_number) {} + explicit Final(unsigned int line_number) : Token(token::final, line_number) {} string show() const override { return "final"; } }; class Abstract : public Token { public: - Abstract(unsigned int line_number) : Token(token::abstract, line_number) {} + explicit Abstract(unsigned int line_number) + : Token(token::abstract, line_number) {} string show() const override { return "abstract"; } }; class Interface : public Token { public: - Interface(unsigned int line_number) : Token(token::interface, line_number) {} + explicit Interface(unsigned int line_number) + : Token(token::interface, line_number) {} string show() const override { return "interface"; } }; class Enum : public Token { public: - Enum(unsigned int line_number) : Token(token::enumToken, line_number) {} + explicit Enum(unsigned int line_number) + : Token(token::enumToken, line_number) {} string show() const override { return "enum"; } }; class Private : public Token { public: - Private(unsigned int line_number) : Token(token::privateToken, line_number) {} + explicit Private(unsigned int line_number) + : Token(token::privateToken, line_number) {} string show() const override { return "private"; } }; class Protected : public Token { public: - Protected(unsigned int line_number) + explicit Protected(unsigned int line_number) : Token(token::protectedToken, line_number) {} string show() const override { return "protected"; } }; class Static : public Token { public: - Static(unsigned int line_number) : Token(token::staticToken, line_number) {} + explicit Static(unsigned int line_number) + : Token(token::staticToken, line_number) {} string show() const override { return "static"; } }; class Volatile : public Token { public: - Volatile(unsigned int line_number) + explicit Volatile(unsigned int line_number) : Token(token::volatileToken, line_number) {} string show() const override { return "volatile"; } }; class Transient : public Token { public: - Transient(unsigned int line_number) : Token(token::transient, line_number) {} + explicit Transient(unsigned int line_number) + : Token(token::transient, line_number) {} string show() const override { return "transient"; } }; class Synchronized : public Token { public: - Synchronized(unsigned int line_number) + explicit Synchronized(unsigned int line_number) : Token(token::synchronized, line_number) {} string show() const override { return "synchronized"; } }; class Native : public Token { public: - Native(unsigned int line_number) : Token(token::native, line_number) {} + explicit Native(unsigned int line_number) + : Token(token::native, line_number) {} string show() const override { return "native"; } }; class Strictfp : public Token { public: - Strictfp(unsigned int line_number) : Token(token::strictfp, line_number) {} + explicit Strictfp(unsigned int line_number) + : Token(token::strictfp, line_number) {} string show() const override { return "strictfp"; } }; class Synthetic : public Token { public: - Synthetic(unsigned int line_number) : Token(token::synthetic, line_number) {} + explicit Synthetic(unsigned int line_number) + : Token(token::synthetic, line_number) {} string show() const override { return "synthetic"; } }; class Bridge : public Token { public: - Bridge(unsigned int line_number) : Token(token::bridge, line_number) {} + explicit Bridge(unsigned int line_number) + : Token(token::bridge, line_number) {} string show() const override { return "bridge"; } }; class Varargs : public Token { public: - Varargs(unsigned int line_number) : Token(token::varargs, line_number) {} + explicit Varargs(unsigned int line_number) + : Token(token::varargs, line_number) {} string show() const override { return "varargs"; } }; class Extends : public Token { public: - Extends(unsigned int line_number) : Token(token::extends, line_number) {} + explicit Extends(unsigned int line_number) + : Token(token::extends, line_number) {} string show() const override { return "extends"; } }; class Implements : public Token { public: - Implements(unsigned int line_number) + explicit Implements(unsigned int line_number) : Token(token::implements, line_number) {} string show() const override { return "implements"; } }; @@ -345,7 +361,8 @@ class Identifier : public Token { class ArrayType : public Token { public: - ArrayType(unsigned int line_number) : Token(token::arrayType, line_number) {} + explicit ArrayType(unsigned int line_number) + : Token(token::arrayType, line_number) {} string show() const override { return "[]"; } }; @@ -360,14 +377,15 @@ class Filepath : public Token { class Include : public Token { public: - Include(unsigned int line_number) : Token(token::include, line_number) {} + explicit Include(unsigned int line_number) + : Token(token::include, line_number) {} string show() const override { return "-include"; } bool is_command() const override { return true; } }; class BaseDirectory : public Token { public: - BaseDirectory(unsigned int line_number) + explicit BaseDirectory(unsigned int line_number) : Token(token::basedirectory, line_number) {} string show() const override { return "-basedirectory"; } bool is_command() const override { return true; } @@ -375,21 +393,23 @@ class BaseDirectory : public Token { class InJars : public Token { public: - InJars(unsigned int line_number) : Token(token::injars, line_number) {} + explicit InJars(unsigned int line_number) + : Token(token::injars, line_number) {} string show() const override { return "-injars "; } bool is_command() const override { return true; } }; class OutJars : public Token { public: - OutJars(unsigned int line_number) : Token(token::outjars, line_number) {} + explicit OutJars(unsigned int line_number) + : Token(token::outjars, line_number) {} string show() const override { return "-outjars "; } bool is_command() const override { return true; } }; class LibraryJars : public Token { public: - LibraryJars(unsigned int line_number) + explicit LibraryJars(unsigned int line_number) : Token(token::libraryjars, line_number) {} string show() const override { return "-libraryjars "; } bool is_command() const override { return true; } @@ -397,7 +417,7 @@ class LibraryJars : public Token { class PrintMapping : public Token { public: - PrintMapping(unsigned int line_number) + explicit PrintMapping(unsigned int line_number) : Token(token::printmapping, line_number) {} string show() const override { return "-printmapping "; } bool is_command() const override { return true; } @@ -405,7 +425,7 @@ class PrintMapping : public Token { class DontObfuscate : public Token { public: - DontObfuscate(unsigned int line_number) + explicit DontObfuscate(unsigned int line_number) : Token(token::dontobfuscate, line_number) {} string show() const override { return "-dontobfuscate "; } bool is_command() const override { return true; } @@ -413,7 +433,7 @@ class DontObfuscate : public Token { class PrintConfiguration : public Token { public: - PrintConfiguration(unsigned int line_number) + explicit PrintConfiguration(unsigned int line_number) : Token(token::printconfiguration, line_number) {} string show() const override { return "-printconfiguration "; } bool is_command() const override { return true; } @@ -421,7 +441,7 @@ class PrintConfiguration : public Token { class PrintSeeds : public Token { public: - PrintSeeds(unsigned int line_number) + explicit PrintSeeds(unsigned int line_number) : Token(token::printseeds, line_number) {} string show() const override { return "-printseeds "; } bool is_command() const override { return true; } @@ -429,7 +449,7 @@ class PrintSeeds : public Token { class DontShrink : public Token { public: - DontShrink(unsigned int line_number) + explicit DontShrink(unsigned int line_number) : Token(token::dontshrink, line_number) {} string show() const override { return "-dontshrink"; } bool is_command() const override { return true; } @@ -437,7 +457,7 @@ class DontShrink : public Token { class PrintUsage : public Token { public: - PrintUsage(unsigned int line_number) + explicit PrintUsage(unsigned int line_number) : Token(token::printusage, line_number) {} string show() const override { return "-printusage"; } bool is_command() const override { return true; } @@ -445,7 +465,7 @@ class PrintUsage : public Token { class WhyAreYouKeeping : public Token { public: - WhyAreYouKeeping(unsigned int line_number) + explicit WhyAreYouKeeping(unsigned int line_number) : Token(token::whyareyoukeeping, line_number) {} string show() const override { return "-whyareyoukeeping"; } bool is_command() const override { return true; } @@ -453,35 +473,35 @@ class WhyAreYouKeeping : public Token { class IncludeDescriptorClasses : public Token { public: - IncludeDescriptorClasses(unsigned int line_number) + explicit IncludeDescriptorClasses(unsigned int line_number) : Token(token::includedescriptorclasses_token, line_number) {} string show() const override { return "includedescriptorclasses"; } }; class AllowOptimization : public Token { public: - AllowOptimization(unsigned int line_number) + explicit AllowOptimization(unsigned int line_number) : Token(token::allowoptimization_token, line_number) {} string show() const override { return "allowshrinking"; } }; class AllowShrinking : public Token { public: - AllowShrinking(unsigned int line_number) + explicit AllowShrinking(unsigned int line_number) : Token(token::allowshrinking_token, line_number) {} string show() const override { return "allowoptimization"; } }; class AllowObfuscation : public Token { public: - AllowObfuscation(unsigned int line_number) + explicit AllowObfuscation(unsigned int line_number) : Token(token::allowobfuscation_token, line_number) {} string show() const override { return "allowobfuscation"; } }; class KeepDirectories : public Token { public: - KeepDirectories(unsigned int line_number) + explicit KeepDirectories(unsigned int line_number) : Token(token::keepdirectories, line_number) {} string show() const override { return "-keepdirectories"; } bool is_command() const override { return true; } @@ -498,14 +518,15 @@ class TargetVersion : public Token { class Target : public Token { public: - Target(unsigned int line_number) : Token(token::target, line_number) {} + explicit Target(unsigned int line_number) + : Token(token::target, line_number) {} string show() const override { return "-target "; } bool is_command() const override { return true; } }; class DontSkipNonPublicLibraryClasses : public Token { public: - DontSkipNonPublicLibraryClasses(unsigned int line_number) + explicit DontSkipNonPublicLibraryClasses(unsigned int line_number) : Token(token::dontskipnonpubliclibraryclasses, line_number) {} string show() const override { return "-dontskipnonpubliclibraryclasses"; } bool is_command() const override { return true; } @@ -513,14 +534,14 @@ class DontSkipNonPublicLibraryClasses : public Token { class Keep : public Token { public: - Keep(unsigned int line_number) : Token(token::keep, line_number) {} + explicit Keep(unsigned int line_number) : Token(token::keep, line_number) {} string show() const override { return "-keep"; } bool is_command() const override { return true; } }; class KeepClassMembers : public Token { public: - KeepClassMembers(unsigned int line_number) + explicit KeepClassMembers(unsigned int line_number) : Token(token::keepclassmembers, line_number) {} string show() const override { return "-keepclassmembers"; } bool is_command() const override { return true; } @@ -528,7 +549,7 @@ class KeepClassMembers : public Token { class KeepClassesWithMembers : public Token { public: - KeepClassesWithMembers(unsigned int line_number) + explicit KeepClassesWithMembers(unsigned int line_number) : Token(token::keepclasseswithmembers, line_number) {} string show() const override { return "-keepclasseswithmembers"; } bool is_command() const override { return true; } @@ -536,14 +557,15 @@ class KeepClassesWithMembers : public Token { class KeepNames : public Token { public: - KeepNames(unsigned int line_number) : Token(token::keepnames, line_number) {} + explicit KeepNames(unsigned int line_number) + : Token(token::keepnames, line_number) {} string show() const override { return "-keepnames"; } bool is_command() const override { return true; } }; class KeepClassMemberNames : public Token { public: - KeepClassMemberNames(unsigned int line_number) + explicit KeepClassMemberNames(unsigned int line_number) : Token(token::keepclassmembernames, line_number) {} string show() const override { return "-keepclassmembernames"; } bool is_command() const override { return true; } @@ -551,7 +573,7 @@ class KeepClassMemberNames : public Token { class KeepClassesWithMemberNames : public Token { public: - KeepClassesWithMemberNames(unsigned int line_number) + explicit KeepClassesWithMemberNames(unsigned int line_number) : Token(token::keepclasseswithmembernames, line_number) {} string show() const override { return "-keepclasseswithmembernames"; } bool is_command() const override { return true; } @@ -559,7 +581,7 @@ class KeepClassesWithMemberNames : public Token { class RepackageClasses : public Token { public: - RepackageClasses(unsigned int line_number) + explicit RepackageClasses(unsigned int line_number) : Token(token::repackageclasses, line_number) {} string show() const override { return "-repackageclasses"; } bool is_command() const override { return true; } @@ -567,7 +589,7 @@ class RepackageClasses : public Token { class Optimizations : public Token { public: - Optimizations(unsigned int line_number) + explicit Optimizations(unsigned int line_number) : Token(token::optimizations, line_number) {} string show() const override { return "-optimizations"; } bool is_command() const override { return true; } @@ -575,7 +597,7 @@ class Optimizations : public Token { class OptimizationPasses : public Token { public: - OptimizationPasses(unsigned int line_number) + explicit OptimizationPasses(unsigned int line_number) : Token(token::optimizationpasses, line_number) {} string show() const override { return "-optimizationpasses"; } bool is_command() const override { return true; } @@ -591,7 +613,7 @@ class Filter : public Token { class KeepAttributes : public Token { public: - KeepAttributes(unsigned int line_number) + explicit KeepAttributes(unsigned int line_number) : Token(token::keepattributes, line_number) {} string show() const override { return "-keepattributes"; } bool is_command() const override { return true; } @@ -599,14 +621,15 @@ class KeepAttributes : public Token { class DontWarn : public Token { public: - DontWarn(unsigned int line_number) : Token(token::dontwarn, line_number) {} + explicit DontWarn(unsigned int line_number) + : Token(token::dontwarn, line_number) {} string show() const override { return "-dontwarn"; } bool is_command() const override { return true; } }; class AssumeSideEffects : public Token { public: - AssumeSideEffects(unsigned int line_number) + explicit AssumeSideEffects(unsigned int line_number) : Token(token::assumenosideeffects, line_number) {} string show() const override { return "-assumenosideeffects"; } bool is_command() const override { return true; } @@ -614,7 +637,7 @@ class AssumeSideEffects : public Token { class AllowAccessModification : public Token { public: - AllowAccessModification(unsigned int line_number) + explicit AllowAccessModification(unsigned int line_number) : Token(token::allowaccessmodification_token, line_number) {} string show() const override { return "-allowaccessmodification"; } bool is_command() const override { return true; } @@ -622,7 +645,7 @@ class AllowAccessModification : public Token { class KeepPackageNames : public Token { public: - KeepPackageNames(unsigned int line_number) + explicit KeepPackageNames(unsigned int line_number) : Token(token::keeppackagenames, line_number) {} string show() const override { return "-keeppackagenames"; } bool is_command() const override { return true; } @@ -630,7 +653,7 @@ class KeepPackageNames : public Token { class DontUseMixedcaseClassNames : public Token { public: - DontUseMixedcaseClassNames(unsigned int line_number) + explicit DontUseMixedcaseClassNames(unsigned int line_number) : Token(token::dontusemixedcaseclassnames_token, line_number) {} string show() const override { return "-dontusemixedcaseclassnames"; } bool is_command() const override { return true; } @@ -638,7 +661,7 @@ class DontUseMixedcaseClassNames : public Token { class DontOptimize : public Token { public: - DontOptimize(unsigned int line_number) + explicit DontOptimize(unsigned int line_number) : Token(token::dontoptimize, line_number) {} string show() const override { return "-dontoptimize"; } bool is_command() const override { return true; } @@ -646,7 +669,7 @@ class DontOptimize : public Token { class MergeInterfacesAggressively : public Token { public: - MergeInterfacesAggressively(unsigned int line_number) + explicit MergeInterfacesAggressively(unsigned int line_number) : Token(token::mergeinterfacesaggressively, line_number) {} string show() const override { return "-mergeinterfacesaggressively"; } bool is_command() const override { return true; } @@ -654,7 +677,7 @@ class MergeInterfacesAggressively : public Token { class DontPreverify : public Token { public: - DontPreverify(unsigned int line_number) + explicit DontPreverify(unsigned int line_number) : Token(token::dontpreverify_token, line_number) {} string show() const override { return "-dontpreverify"; } bool is_command() const override { return true; } @@ -662,7 +685,7 @@ class DontPreverify : public Token { class Verbose : public Token { public: - Verbose(unsigned int line_number) + explicit Verbose(unsigned int line_number) : Token(token::verbose_token, line_number) {} string show() const override { return "-verbose"; } bool is_command() const override { return true; } @@ -681,7 +704,8 @@ class UnknownToken : public Token { class EndOfFile : public Token { public: - EndOfFile(unsigned int line_number) : Token(token::eof_token, line_number) {} + explicit EndOfFile(unsigned int line_number) + : Token(token::eof_token, line_number) {} string show() const override { return ""; } }; diff --git a/libredex/RedexContext.h b/libredex/RedexContext.h index 28ffa498899..992eb730443 100644 --- a/libredex/RedexContext.h +++ b/libredex/RedexContext.h @@ -45,7 +45,7 @@ extern "C" bool strcmp_less(const char* str1, const char* str2); #endif struct RedexContext { - RedexContext(bool allow_class_duplicates = false); + explicit RedexContext(bool allow_class_duplicates = false); ~RedexContext(); DexString* make_string(const char* nstr, uint32_t utfsize); diff --git a/libredex/RedexException.h b/libredex/RedexException.h index 3e336348b59..95a35fa4c82 100644 --- a/libredex/RedexException.h +++ b/libredex/RedexException.h @@ -29,9 +29,10 @@ class RedexException : public std::exception { const std::string message; const std::map extra_info; - RedexException(RedexError type_of_error, - const std::string& message = "", - const std::map& extra_info = {}); + explicit RedexException( + RedexError type_of_error, + const std::string& message = "", + const std::map& extra_info = {}); const char* what() const throw() override; diff --git a/libredex/StringBuilder.h b/libredex/StringBuilder.h index 5a3ec86a73b..8142265eb24 100644 --- a/libredex/StringBuilder.h +++ b/libredex/StringBuilder.h @@ -60,7 +60,7 @@ class StaticStringBuilder { class DynamicStringBuilder { public: - DynamicStringBuilder(uint32_t expected_num_strings) { + explicit DynamicStringBuilder(uint32_t expected_num_strings) { m_strings.reserve(expected_num_strings); } diff --git a/libredex/Timer.h b/libredex/Timer.h index 8e7e8040c24..0e5d44db2d7 100644 --- a/libredex/Timer.h +++ b/libredex/Timer.h @@ -14,7 +14,7 @@ #include struct Timer { - Timer(const std::string& msg); + explicit Timer(const std::string& msg); ~Timer(); using times_t = std::vector>; diff --git a/libredex/TypeInference.h b/libredex/TypeInference.h index 5760a7f0f5e..0320677949f 100644 --- a/libredex/TypeInference.h +++ b/libredex/TypeInference.h @@ -182,7 +182,7 @@ class TypeEnvironment final class TypeInference final : public ir_analyzer::BaseIRAnalyzer { public: - TypeInference(const cfg::ControlFlowGraph& cfg) + explicit TypeInference(const cfg::ControlFlowGraph& cfg) : ir_analyzer::BaseIRAnalyzer(cfg), m_cfg(cfg) {} void run(const DexMethod* dex_method); diff --git a/libredex/Vinfo.h b/libredex/Vinfo.h index f4672108971..a65874e3a6b 100644 --- a/libredex/Vinfo.h +++ b/libredex/Vinfo.h @@ -46,7 +46,7 @@ class Vinfo { }; using vinfos_t = std::unordered_map; - Vinfo(const std::vector& scope); + explicit Vinfo(const std::vector& scope); /** * Finds the topmost declaration of this method. diff --git a/libredex/Walkers.h b/libredex/Walkers.h index 73b8867125b..2bedc8c0c31 100644 --- a/libredex/Walkers.h +++ b/libredex/Walkers.h @@ -31,8 +31,10 @@ template class CacheAligned { public: template + // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions) CacheAligned(Args&&... args) : m_aligned(std::forward(args)...) {} + // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions) inline operator T&(); private: diff --git a/libredex/WorkQueue.h b/libredex/WorkQueue.h index 2865f8a2a7b..9c0961d47bb 100644 --- a/libredex/WorkQueue.h +++ b/libredex/WorkQueue.h @@ -62,7 +62,7 @@ inline std::vector create_permutation(int num, unsigned int thread_idx) { template class WorkerState { public: - WorkerState(size_t id) : m_id(id) {} + explicit WorkerState(size_t id) : m_id(id) {} /* * Add more items to the queue of the currently-running worker. When a diff --git a/opt/constant-propagation/ConstantPropagationRuntimeAssert.h b/opt/constant-propagation/ConstantPropagationRuntimeAssert.h index b4e0addb0ba..83c89824c1e 100644 --- a/opt/constant-propagation/ConstantPropagationRuntimeAssert.h +++ b/opt/constant-propagation/ConstantPropagationRuntimeAssert.h @@ -26,10 +26,10 @@ class RuntimeAssertTransform { DexMethodRef* field_assert_fail_handler{nullptr}; DexMethodRef* return_value_assert_fail_handler{nullptr}; Config() = default; - Config(const ProguardMap&); + explicit Config(const ProguardMap&); }; - RuntimeAssertTransform(const Config& config) : m_config(config) {} + explicit RuntimeAssertTransform(const Config& config) : m_config(config) {} void apply(const intraprocedural::FixpointIterator&, const WholeProgramState&, diff --git a/opt/constant-propagation/IPConstantPropagation.h b/opt/constant-propagation/IPConstantPropagation.h index 1b79d3f2928..ee2ae431dc2 100644 --- a/opt/constant-propagation/IPConstantPropagation.h +++ b/opt/constant-propagation/IPConstantPropagation.h @@ -33,7 +33,7 @@ class PassImpl : public Pass { RuntimeAssertTransform::Config runtime_assert; }; - PassImpl(Config config) + explicit PassImpl(Config config) : Pass("InterproceduralConstantPropagationPass"), m_config(std::move(config)) {} diff --git a/opt/dedup-strings/DedupStrings.cpp b/opt/dedup-strings/DedupStrings.cpp index 53a4b57a89f..85394d49e40 100644 --- a/opt/dedup-strings/DedupStrings.cpp +++ b/opt/dedup-strings/DedupStrings.cpp @@ -649,7 +649,7 @@ void DedupStrings::rewrite_const_string_instructions( class DedupStringsInterDexPlugin : public interdex::InterDexPassPlugin { public: - DedupStringsInterDexPlugin(size_t max_factory_methods) + explicit DedupStringsInterDexPlugin(size_t max_factory_methods) : m_max_factory_methods(max_factory_methods) {} size_t reserve_mrefs() override { // In each, we might introduce as many new method refs are we might add diff --git a/opt/final_inline/FinalInlineV2.cpp b/opt/final_inline/FinalInlineV2.cpp index 4f26af15526..3c3c8b3e9e7 100644 --- a/opt/final_inline/FinalInlineV2.cpp +++ b/opt/final_inline/FinalInlineV2.cpp @@ -162,7 +162,7 @@ using CombinedInitAnalyzer = */ class encoding_visitor : public boost::static_visitor { public: - encoding_visitor(const DexField* field) : m_field(field) {} + explicit encoding_visitor(const DexField* field) : m_field(field) {} DexEncodedValue* operator()(const SignedConstantDomain& dom) const { auto cst = dom.get_constant(); diff --git a/opt/final_inline/FinalInlineV2.h b/opt/final_inline/FinalInlineV2.h index 6aa84b0b66f..85a46908131 100644 --- a/opt/final_inline/FinalInlineV2.h +++ b/opt/final_inline/FinalInlineV2.h @@ -50,7 +50,7 @@ namespace final_inline { class class_initialization_cycle : public std::exception { public: - class_initialization_cycle(const DexClass* cls) { + explicit class_initialization_cycle(const DexClass* cls) { m_msg = "Found a class initialization cycle involving " + show(cls); } diff --git a/opt/instrument/Instrument.cpp b/opt/instrument/Instrument.cpp index 112d9f6f458..72febe7cb61 100644 --- a/opt/instrument/Instrument.cpp +++ b/opt/instrument/Instrument.cpp @@ -38,7 +38,7 @@ static bool debug = false; class InstrumentInterDexPlugin : public interdex::InterDexPassPlugin { public: - InstrumentInterDexPlugin(size_t max_analysis_methods) + explicit InstrumentInterDexPlugin(size_t max_analysis_methods) : m_max_analysis_methods(max_analysis_methods) {} void configure(const Scope& scope, ConfigFiles& cfg) override{}; diff --git a/opt/interdex/CrossDexRefMinimizer.h b/opt/interdex/CrossDexRefMinimizer.h index 843614fd039..175f3624757 100644 --- a/opt/interdex/CrossDexRefMinimizer.h +++ b/opt/interdex/CrossDexRefMinimizer.h @@ -88,7 +88,7 @@ class CrossDexRefMinimizer { uint64_t refs_weight; uint64_t applied_refs_weight; uint64_t seed_weight{0}; - ClassInfo(uint32_t i) + explicit ClassInfo(uint32_t i) : index(i), infrequent_refs_weight(), refs_weight(0), @@ -121,7 +121,7 @@ class CrossDexRefMinimizer { std::vector& strings); public: - CrossDexRefMinimizer(const CrossDexRefMinimizerConfig& config) + explicit CrossDexRefMinimizer(const CrossDexRefMinimizerConfig& config) : m_config(config) {} // Gather frequency counts; must be called for relevant classes before // inserting them diff --git a/opt/interdex/InterDexPass.h b/opt/interdex/InterDexPass.h index b4bec4d5ca8..49e40143252 100644 --- a/opt/interdex/InterDexPass.h +++ b/opt/interdex/InterDexPass.h @@ -44,7 +44,8 @@ constexpr const char* METRIC_RELOCATED_VIRTUAL_METHODS = class InterDexPass : public Pass { public: - InterDexPass(bool register_plugins = true) : Pass(INTERDEX_PASS_NAME) { + explicit InterDexPass(bool register_plugins = true) + : Pass(INTERDEX_PASS_NAME) { if (register_plugins) { std::unique_ptr plugin = std::make_unique(); diff --git a/opt/obfuscate/ObfuscateUtils.h b/opt/obfuscate/ObfuscateUtils.h index 245c402ce68..af9bd86e516 100644 --- a/opt/obfuscate/ObfuscateUtils.h +++ b/opt/obfuscate/ObfuscateUtils.h @@ -13,6 +13,7 @@ #include "DexUtil.h" #include "ReachableClasses.h" #include +#include namespace obfuscate_utils { void compute_identifier(int value, std::string* res); @@ -46,7 +47,8 @@ bool should_rename_elem(const T* member) { * vmethods (requires some additional information). Additionally, some record * of the old name is necessary to fix up ref opcodes. */ -template +template ::value, int>::type = 0> class DexNameWrapper { protected: T dex_elem; @@ -55,6 +57,8 @@ class DexNameWrapper { std::string name{"INVALID_DEFAULT_NAME"}; public: + using const_type = typename std::add_const::type; + // Default constructor is only ever used for map template to work correctly // we have added asserts to make sure there are no nullptrs returned. DexNameWrapper() = default; @@ -72,7 +76,7 @@ class DexNameWrapper { always_assert(dex_elem != nullptr); return dex_elem; } - inline const T get() const { + inline const_type get() const { always_assert(dex_elem != nullptr); return dex_elem; } diff --git a/opt/object-sensitive-dce/ObjectSensitiveDcePass.cpp b/opt/object-sensitive-dce/ObjectSensitiveDcePass.cpp index f34d96e7e42..5e213e75046 100644 --- a/opt/object-sensitive-dce/ObjectSensitiveDcePass.cpp +++ b/opt/object-sensitive-dce/ObjectSensitiveDcePass.cpp @@ -42,7 +42,7 @@ namespace uv = used_vars; class CallGraphStrategy final : public call_graph::BuildStrategy { public: - CallGraphStrategy(const Scope& scope) + explicit CallGraphStrategy(const Scope& scope) : m_scope(scope), m_non_overridden_virtuals(hier::find_non_overridden_virtuals(scope)) {} diff --git a/opt/optimize_enums/EnumClinitAnalysis.cpp b/opt/optimize_enums/EnumClinitAnalysis.cpp index 99c7ef235fa..438b78deed2 100644 --- a/opt/optimize_enums/EnumClinitAnalysis.cpp +++ b/opt/optimize_enums/EnumClinitAnalysis.cpp @@ -67,6 +67,7 @@ DexField* get_enum_name_field() { } struct EnumOrdinalAnalyzerState { + // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions) /* implicit */ EnumOrdinalAnalyzerState(const DexType* clinit_class) : clinit_class(clinit_class) { auto& fields = type_class(clinit_class)->get_ifields(); diff --git a/opt/optimize_enums/OptimizeEnumsGeneratedAnalysis.cpp b/opt/optimize_enums/OptimizeEnumsGeneratedAnalysis.cpp index e939107d225..714cf91433f 100644 --- a/opt/optimize_enums/OptimizeEnumsGeneratedAnalysis.cpp +++ b/opt/optimize_enums/OptimizeEnumsGeneratedAnalysis.cpp @@ -207,7 +207,7 @@ class ConstAnalyzer final UInt32ConstantEnvironment> { public: - ConstAnalyzer(const cfg::ControlFlowGraph& cfg) + explicit ConstAnalyzer(const cfg::ControlFlowGraph& cfg) : MonotonicFixpointIterator(cfg) { MonotonicFixpointIterator::run(UInt32ConstantEnvironment::top()); } diff --git a/opt/reduce-array-literals/ReduceArrayLiterals.cpp b/opt/reduce-array-literals/ReduceArrayLiterals.cpp index 9a42946e72c..188a7e83d39 100644 --- a/opt/reduce-array-literals/ReduceArrayLiterals.cpp +++ b/opt/reduce-array-literals/ReduceArrayLiterals.cpp @@ -183,7 +183,7 @@ using TrackedDomainEnvironment = class Analyzer final : public BaseIRAnalyzer { public: - Analyzer(cfg::ControlFlowGraph& cfg) : BaseIRAnalyzer(cfg) { + explicit Analyzer(cfg::ControlFlowGraph& cfg) : BaseIRAnalyzer(cfg) { MonotonicFixpointIterator::run(TrackedDomainEnvironment::top()); } diff --git a/opt/regalloc/GraphColoring.h b/opt/regalloc/GraphColoring.h index 877480bc45e..db67f061f69 100644 --- a/opt/regalloc/GraphColoring.h +++ b/opt/regalloc/GraphColoring.h @@ -103,7 +103,7 @@ class Allocator { Allocator() = default; // use default config - Allocator(const Config& config) : m_config(config) {} + explicit Allocator(const Config& config) : m_config(config) {} bool coalesce(interference::Graph*, IRCode*); diff --git a/opt/result-propagation/ResultPropagation.h b/opt/result-propagation/ResultPropagation.h index ccf05294e69..6b6a59a6422 100644 --- a/opt/result-propagation/ResultPropagation.h +++ b/opt/result-propagation/ResultPropagation.h @@ -29,7 +29,7 @@ std::unordered_map get_load_param_map( */ class ReturnParamResolver { public: - ReturnParamResolver(const method_override_graph::Graph& graph) + explicit ReturnParamResolver(const method_override_graph::Graph& graph) : m_graph(graph), m_byte_buffer_type(DexType::make_type("Ljava/nio/ByteBuffer;")), m_char_buffer_type(DexType::make_type("Ljava/nio/CharBuffer;")), diff --git a/opt/string_concatenator/StringConcatenator.cpp b/opt/string_concatenator/StringConcatenator.cpp index a3390e411a4..7dcd2dbce78 100644 --- a/opt/string_concatenator/StringConcatenator.cpp +++ b/opt/string_concatenator/StringConcatenator.cpp @@ -326,7 +326,7 @@ class Concatenator { } public: - Concatenator(const ConcatenatorConfig& config) : m_config(config) {} + explicit Concatenator(const ConcatenatorConfig& config) : m_config(config) {} Stats run(cfg::ControlFlowGraph* cfg, DexMethod* method, diff --git a/opt/stringbuilder-outliner/StringBuilderOutliner.h b/opt/stringbuilder-outliner/StringBuilderOutliner.h index d41ab320729..56a3af944d6 100644 --- a/opt/stringbuilder-outliner/StringBuilderOutliner.h +++ b/opt/stringbuilder-outliner/StringBuilderOutliner.h @@ -168,7 +168,7 @@ using Environment = local_pointers::EnvironmentWithStoreImpl; class FixpointIterator final : public ir_analyzer::BaseIRAnalyzer { public: - FixpointIterator(const cfg::ControlFlowGraph& cfg); + explicit FixpointIterator(const cfg::ControlFlowGraph& cfg); void analyze_instruction(const IRInstruction* insn, Environment* env) const override; @@ -202,7 +202,7 @@ struct Stats { class Outliner { public: - Outliner(Config config = Config()); + explicit Outliner(Config config = Config()); const Config& get_config() const { return m_config; } diff --git a/service/class-init/ClassInitCounter.h b/service/class-init/ClassInitCounter.h index 555155e28a7..1b6305f9c5f 100644 --- a/service/class-init/ClassInitCounter.h +++ b/service/class-init/ClassInitCounter.h @@ -174,7 +174,7 @@ enum Tracked { // TrackedUses is the 'abstract' parent class of the domain representation class TrackedUses { public: - TrackedUses(Tracked kind); + explicit TrackedUses(Tracked kind); virtual ~TrackedUses(); /* @@ -235,7 +235,7 @@ class MergedUses : public TrackedUses { public: MergedUses(const ObjectUses&, const ObjectUses&); // Creates a merged object where nullable is true - MergedUses(const ObjectUses&); + explicit MergedUses(const ObjectUses&); void combine_paths(const TrackedUses& other); void merge(const TrackedUses& other); @@ -378,7 +378,7 @@ class InitLocation final { dexclasses_comparator>; public: - InitLocation(DexType* typ) : m_typ(typ) {} + explicit InitLocation(DexType* typ) : m_typ(typ) {} InitLocation() = default; uint32_t get_count() const { return m_count; } diff --git a/service/constant-propagation/ConstantArrayDomain.h b/service/constant-propagation/ConstantArrayDomain.h index ba760547e84..2d5f550d910 100644 --- a/service/constant-propagation/ConstantArrayDomain.h +++ b/service/constant-propagation/ConstantArrayDomain.h @@ -66,7 +66,7 @@ class ConstantArrayDomain final "Domain::default_value() does not exist"); } - ConstantArrayDomain(uint32_t length) { + explicit ConstantArrayDomain(uint32_t length) { mutate_array_length( [length](ArrayLengthDomain* len) { *len = ArrayLengthDomain(length); }); mutate_array_values([length](ArrayValuesDomain* values) { diff --git a/service/constant-propagation/ConstantPropagationTransform.h b/service/constant-propagation/ConstantPropagationTransform.h index a75a1be4d90..971f46c247a 100644 --- a/service/constant-propagation/ConstantPropagationTransform.h +++ b/service/constant-propagation/ConstantPropagationTransform.h @@ -100,7 +100,7 @@ class Transform final { class value_to_instruction_visitor final : public boost::static_visitor> { public: - value_to_instruction_visitor(const IRInstruction* original) + explicit value_to_instruction_visitor(const IRInstruction* original) : m_original(original) {} std::vector operator()( diff --git a/service/constant-propagation/ObjectWithImmutAttr.h b/service/constant-propagation/ObjectWithImmutAttr.h index 537ec1932fe..b2f40fe6171 100644 --- a/service/constant-propagation/ObjectWithImmutAttr.h +++ b/service/constant-propagation/ObjectWithImmutAttr.h @@ -53,10 +53,10 @@ struct ImmutableAttr { const DexMethod* method; const void* member; // Debug only. }; - Attr(const DexField* f) : kind(Field), field(f) { + explicit Attr(const DexField* f) : kind(Field), field(f) { always_assert(!field->is_def() || (!is_static(field) && is_final(field))); } - Attr(const DexMethod* m) : kind(Method), method(m) { + explicit Attr(const DexMethod* m) : kind(Method), method(m) { if (method->is_def()) { always_assert(!is_static(method) && !is_constructor(method)); } diff --git a/service/cse/CommonSubexpressionElimination.h b/service/cse/CommonSubexpressionElimination.h index 57aad7a96d2..637e1eff70f 100644 --- a/service/cse/CommonSubexpressionElimination.h +++ b/service/cse/CommonSubexpressionElimination.h @@ -57,7 +57,7 @@ struct BarrierHasher { class SharedState { public: - SharedState(const std::unordered_set& pure_methods); + explicit SharedState(const std::unordered_set& pure_methods); void init_scope(const Scope&); CseUnorderedLocationSet get_relevant_written_locations( const IRInstruction* insn, diff --git a/service/dataflow/LiveRange.cpp b/service/dataflow/LiveRange.cpp index b496ab9ea6d..030ca1cab5a 100644 --- a/service/dataflow/LiveRange.cpp +++ b/service/dataflow/LiveRange.cpp @@ -33,7 +33,7 @@ using DefSets = boost::disjoint_sets; */ class SymRegMapper { public: - SymRegMapper(bool width_aware) : m_width_aware(width_aware) {} + explicit SymRegMapper(bool width_aware) : m_width_aware(width_aware) {} reg_t make(Def def) { if (m_def_to_reg.find(def) == m_def_to_reg.end()) { diff --git a/service/dataflow/Liveness.h b/service/dataflow/Liveness.h index bc5c784b385..dc326d6642e 100644 --- a/service/dataflow/Liveness.h +++ b/service/dataflow/Liveness.h @@ -16,7 +16,7 @@ using LivenessDomain = sparta::PatriciaTreeSetAbstractDomain; class LivenessFixpointIterator final : public ir_analyzer::BaseBackwardsIRAnalyzer { public: - LivenessFixpointIterator(const cfg::ControlFlowGraph& cfg) + explicit LivenessFixpointIterator(const cfg::ControlFlowGraph& cfg) : ir_analyzer::BaseBackwardsIRAnalyzer(cfg) {} void analyze_instruction(IRInstruction* insn, diff --git a/service/method-merger/MethodMerger.cpp b/service/method-merger/MethodMerger.cpp index 0c144b42597..1c6ffbcfddf 100644 --- a/service/method-merger/MethodMerger.cpp +++ b/service/method-merger/MethodMerger.cpp @@ -55,7 +55,7 @@ std::unordered_set methodgroups_to_methodset( */ class RefCounter { public: - RefCounter(method_reference::CallSites& call_sites) { + explicit RefCounter(method_reference::CallSites& call_sites) { for (auto& callsite : call_sites) { ++m_counter[callsite.callee]; } diff --git a/service/reference-update/MethodReference.h b/service/reference-update/MethodReference.h index 906489da6e0..a7978ddeca1 100644 --- a/service/reference-update/MethodReference.h +++ b/service/reference-update/MethodReference.h @@ -32,7 +32,7 @@ struct NewCallee { DexMethod* method; boost::optional> additional_args = boost::none; - NewCallee(DexMethod* method) : method(method) {} + explicit NewCallee(DexMethod* method) : method(method) {} NewCallee(DexMethod* method, boost::optional arg) : method(method) { if (arg == boost::none) { return; diff --git a/service/reference-update/TypeReference.h b/service/reference-update/TypeReference.h index 4de7dad22a9..3836d217456 100644 --- a/service/reference-update/TypeReference.h +++ b/service/reference-update/TypeReference.h @@ -40,7 +40,8 @@ class TypeRefUpdater final { * trying to update a virtual method that may override any external virtual * method. */ - TypeRefUpdater(const std::unordered_map& old_to_new); + explicit TypeRefUpdater( + const std::unordered_map& old_to_new); void update_methods_fields(const Scope& scope); diff --git a/service/switch-partitioning/SwitchMethodPartitioning.h b/service/switch-partitioning/SwitchMethodPartitioning.h index 582507fd89d..c8092bdbba1 100644 --- a/service/switch-partitioning/SwitchMethodPartitioning.h +++ b/service/switch-partitioning/SwitchMethodPartitioning.h @@ -45,7 +45,8 @@ */ class SwitchMethodPartitioning final { public: - SwitchMethodPartitioning(IRCode* code, bool verify_default_case = true); + explicit SwitchMethodPartitioning(IRCode* code, + bool verify_default_case = true); // Each SMP instance is responsible for clearing the CFG of m_code exactly // once, so we don't want to have multiple copies of it. diff --git a/service/type-string-rewriter/TypeStringRewriter.h b/service/type-string-rewriter/TypeStringRewriter.h index 6d10263810b..5c2e8f6b189 100644 --- a/service/type-string-rewriter/TypeStringRewriter.h +++ b/service/type-string-rewriter/TypeStringRewriter.h @@ -22,7 +22,7 @@ class TypeStringMap { public: TypeStringMap() {} - TypeStringMap( + explicit TypeStringMap( const std::unordered_map& type_mapping); /** * Add type mapping from old_name to new_name. diff --git a/test/integ/PeepholeTest.cpp b/test/integ/PeepholeTest.cpp index 77aeda0ae7c..9f90f51feb0 100644 --- a/test/integ/PeepholeTest.cpp +++ b/test/integ/PeepholeTest.cpp @@ -29,7 +29,7 @@ struct IRInstructionList { std::vector> instructions; - explicit IRInstructionList(std::initializer_list in) { + IRInstructionList(std::initializer_list in) { for (IRInstruction* insn : in) { instructions.emplace_back(insn); // moves insn into unique_ptr } diff --git a/test/unit/ConfigurableTest.cpp b/test/unit/ConfigurableTest.cpp index fac979e7577..c0a4240e705 100644 --- a/test/unit/ConfigurableTest.cpp +++ b/test/unit/ConfigurableTest.cpp @@ -32,7 +32,7 @@ struct Base : public Configurable { }; struct BadBindFlags : public Base { - BadBindFlags(bindflags_t bindflags = 0) { m_bindflags = bindflags; } + explicit BadBindFlags(bindflags_t bindflags = 0) { m_bindflags = bindflags; } void bind_config() override { bind("int_param", 0, m_int_param, "", m_bindflags); } @@ -73,7 +73,7 @@ TEST_F(ConfigurableTest, BadBindFlags) { } struct OptionalBindings : public Base { - OptionalBindings(bindflags_t optional_string_bindflags) { + explicit OptionalBindings(bindflags_t optional_string_bindflags) { m_optional_string_bindflags = optional_string_bindflags; } void bind_config() override { @@ -255,7 +255,9 @@ TEST_F(ConfigurableTest, CompositeBindings) { } struct TypesBindFlags : public Base { - TypesBindFlags(bindflags_t bindflags = 0) { m_bindflags = bindflags; } + explicit TypesBindFlags(bindflags_t bindflags = 0) { + m_bindflags = bindflags; + } void bind_config() override { bind("types_param", {}, m_types_param, "", m_bindflags); } @@ -304,7 +306,9 @@ TEST_F(ConfigurableTest, TypesBindFlags) { } struct MethodsBindFlags : public Base { - MethodsBindFlags(bindflags_t bindflags = 0) { m_bindflags = bindflags; } + explicit MethodsBindFlags(bindflags_t bindflags = 0) { + m_bindflags = bindflags; + } void bind_config() override { bind("methods_param", {}, m_methods_param, "", m_bindflags); } @@ -369,7 +373,7 @@ TEST_F(ConfigurableTest, MethodsBindFlags) { } struct AfterConfiguration : public Base { - AfterConfiguration(int iterations) + explicit AfterConfiguration(int iterations) : m_after_config_called(false), m_iterations(iterations) {} void bind_config() override { for (int i = 0; i < m_iterations; ++i) { diff --git a/test/unit/RemoveUninstantiablesTest.cpp b/test/unit/RemoveUninstantiablesTest.cpp index 4a972c95936..911bf6caf25 100644 --- a/test/unit/RemoveUninstantiablesTest.cpp +++ b/test/unit/RemoveUninstantiablesTest.cpp @@ -463,7 +463,7 @@ TEST_F(RemoveUninstantiablesTest, ReplaceAllWithThrow) { } TEST_F(RemoveUninstantiablesTest, RunPass) { - DexStoresVector dss{{"test_store"}}; + DexStoresVector dss{DexStore{"test_store"}}; auto* Foo = def_class("LFoo;", Foo_baz, Foo_qux); auto* Bar = def_class("LBar;", Bar_init, Bar_baz, Bar_qux); diff --git a/util/JemallocUtil.h b/util/JemallocUtil.h index ced3ca13c6e..e8e8ebd06a8 100644 --- a/util/JemallocUtil.h +++ b/util/JemallocUtil.h @@ -15,7 +15,7 @@ void disable_profiling(); class ScopedProfiling final { public: - ScopedProfiling(bool enable) { + explicit ScopedProfiling(bool enable) { if (enable) { fprintf(stderr, "Enabling memory profiling...\n"); enable_profiling();