diff --git a/examples/make_hello_c/sim_main.cpp b/examples/make_hello_c/sim_main.cpp index f2df7b52e..1a9ace25e 100644 --- a/examples/make_hello_c/sim_main.cpp +++ b/examples/make_hello_c/sim_main.cpp @@ -19,14 +19,14 @@ int main(int argc, char** argv) { // e.g. examples/c_tracing. // Construct a VerilatedContext to hold simulation time, etc. - VerilatedContext* contextp = new VerilatedContext; + VerilatedContext* const contextp = new VerilatedContext; // Pass arguments so Verilated code can see them, e.g. $value$plusargs // This needs to be called before you create any model contextp->commandArgs(argc, argv); // Construct the Verilated model, from Vtop.h generated from Verilating "top.v" - Vtop* top = new Vtop{contextp}; + Vtop* const top = new Vtop{contextp}; // Simulate until $finish while (!contextp->gotFinish()) { diff --git a/examples/make_hello_sc/sc_main.cpp b/examples/make_hello_sc/sc_main.cpp index 5f9ab2429..697dcd973 100644 --- a/examples/make_hello_sc/sc_main.cpp +++ b/examples/make_hello_sc/sc_main.cpp @@ -25,7 +25,7 @@ int sc_main(int argc, char* argv[]) { // e.g. examples/c_tracing. // Construct the Verilated model, from Vtop.h generated from Verilating "top.v" - Vtop* top = new Vtop{"top"}; + Vtop* const top = new Vtop{"top"}; // Pass arguments so Verilated code can see them, e.g. $value$plusargs // This needs to be called before you create any model diff --git a/examples/make_protect_lib/sim_main.cpp b/examples/make_protect_lib/sim_main.cpp index 0c11180f5..03697a316 100644 --- a/examples/make_protect_lib/sim_main.cpp +++ b/examples/make_protect_lib/sim_main.cpp @@ -20,13 +20,13 @@ int main(int argc, char** argv) { if (false && argc && argv) {} // Construct context to hold simulation time, etc - VerilatedContext* contextp = new VerilatedContext; + const std::unique_ptr contextp{new VerilatedContext}; contextp->debug(0); contextp->randReset(2); contextp->commandArgs(argc, argv); // Construct the Verilated model, including the secret module - Vtop* top = new Vtop{contextp}; + const std::unique_ptr top{new Vtop{contextp.get(), "TOP"}}; #if VM_TRACE // When tracing, the contents of the secret module will not be seen @@ -65,12 +65,6 @@ int main(int argc, char** argv) { } #endif - // Destroy model - delete top; - top = nullptr; - delete contextp; - contextp = nullptr; - // Return good completion status // Don't use exit() or destructor won't get called return 0; diff --git a/include/verilated.cpp b/include/verilated.cpp index cd0ee1122..948e1ca57 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -791,7 +791,7 @@ std::string _vl_vsformat_time(char* tmp, T ld, int timeunit, bool left, size_t w } } - const int needmore = width - digits; + const int needmore = static_cast(width) - digits; std::string padding; if (needmore > 0) padding.append(needmore, ' '); // Pad with spaces return left ? (tmp + padding) : (padding + tmp); @@ -947,9 +947,9 @@ void _vl_vsformat(std::string& output, const std::string& format, va_list ap) VL } else { append = VL_DECIMAL_NW(lbits, lwp); } - digits = append.length(); + digits = static_cast(append.length()); } - const int needmore = width - digits; + const int needmore = static_cast(width) - digits; if (needmore > 0) { std::string padding; if (left) { @@ -976,9 +976,9 @@ void _vl_vsformat(std::string& output, const std::string& format, va_list ap) VL append = t_tmp; } else { append = VL_DECIMAL_NW(lbits, lwp); - digits = append.length(); + digits = static_cast(append.length()); } - const int needmore = width - digits; + const int needmore = static_cast(width) - digits; if (needmore > 0) { std::string padding; if (left) { @@ -1044,7 +1044,7 @@ void _vl_vsformat(std::string& output, const std::string& format, va_list ap) VL } } // switch - const int needmore = width - digits; + const int needmore = static_cast(width) - digits; if (needmore > 0) { std::string padding; if (left) { diff --git a/include/verilated_imp.h b/include/verilated_imp.h index 57626a2d2..3066ba44d 100644 --- a/include/verilated_imp.h +++ b/include/verilated_imp.h @@ -294,7 +294,7 @@ public: // But only for verilated*.cpp std::fill(m_fdps.begin() + start, m_fdps.end(), static_cast(nullptr)); m_fdFree.resize(excess); for (std::size_t i = 0, id = start; i < m_fdFree.size(); ++i, ++id) { - m_fdFree[i] = id; + m_fdFree[i] = static_cast(id); } } const IData idx = m_fdFree.back(); diff --git a/include/verilated_threads.h b/include/verilated_threads.h index 12b552e59..7ba0a4f33 100644 --- a/include/verilated_threads.h +++ b/include/verilated_threads.h @@ -214,10 +214,10 @@ public: ~VlThreadPool() override; // METHODS - int numThreads() const { return m_workers.size(); } + int numThreads() const { return static_cast(m_workers.size()); } VlWorkerThread* workerp(int index) { assert(index >= 0); - assert(static_cast(index) < m_workers.size()); + assert(index < static_cast(m_workers.size())); return m_workers[index]; }