From f6b232f239fe313d2bf473f2f489b1e7da552756 Mon Sep 17 00:00:00 2001 From: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:31:19 +0900 Subject: [PATCH] Suppress Clang++ warnings on macOS (#2205) * Suppress Clang++ warnings * clang-format --- src/framework/operations.hpp | 13 +++++++++++++ src/simulators/matrix_product_state/svd.cpp | 6 +++--- src/simulators/parallel_state_executor.hpp | 2 +- src/simulators/statevector/statevector_state.hpp | 2 +- src/simulators/superoperator/superoperator.hpp | 2 +- src/simulators/tensor_network/tensor_net_state.hpp | 6 ++++-- src/simulators/unitary/unitary_state.hpp | 2 +- src/transpile/fusion.hpp | 13 ++++++++----- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/framework/operations.hpp b/src/framework/operations.hpp index f6c727c2b6..a70319357a 100644 --- a/src/framework/operations.hpp +++ b/src/framework/operations.hpp @@ -103,6 +103,7 @@ class CExpr { : expr_type(_expr_type), type(_type) {} virtual bool eval_bool(const std::string &memory) { return false; }; virtual uint_t eval_uint(const std::string &memory) { return 0ul; }; + virtual ~CExpr() = default; public: const CExprType expr_type; @@ -139,6 +140,8 @@ class CastExpr : public CExpr { throw std::invalid_argument(R"(invalid cast: from unknown type.)"); } + virtual ~CastExpr() = default; + public: const std::shared_ptr operand; }; @@ -163,6 +166,8 @@ class VarExpr : public CExpr { return eval_uint_(memory); } + virtual ~VarExpr() = default; + private: uint_t eval_uint_(const std::string &memory) { uint_t val = 0ul; @@ -199,6 +204,8 @@ class UintValue : public ValueExpr { virtual uint_t eval_uint(const std::string &memory) { return value; } + virtual ~UintValue() = default; + public: const uint_t value; }; @@ -215,6 +222,8 @@ class BoolValue : public ValueExpr { R"(eval_uint is called for Bool value without cast.)"); } + virtual ~BoolValue() = default; + public: const bool value; }; @@ -246,6 +255,8 @@ class UnaryExpr : public CExpr { throw std::invalid_argument(R"(should not reach here.)"); } + virtual ~UnaryExpr() = default; + public: const UnaryOp op; const std::shared_ptr operand; @@ -358,6 +369,8 @@ class BinaryExpr : public CExpr { } } + virtual ~BinaryExpr() = default; + public: const BinaryOp op; const std::shared_ptr left; diff --git a/src/simulators/matrix_product_state/svd.cpp b/src/simulators/matrix_product_state/svd.cpp index f757e79065..aa0d318423 100644 --- a/src/simulators/matrix_product_state/svd.cpp +++ b/src/simulators/matrix_product_state/svd.cpp @@ -632,7 +632,7 @@ void lapack_csvd_wrapper(cmatrix_t &A, cmatrix_t &U, rvector_t &S, zgesdd_("A", &m, &n, lapackA, &m, lapackS, lapackU, &m, lapackV, &n, work_, &lwork, rwork, iwork, &info); - delete iwork; + delete[] iwork; free(rwork); free(work_); } else { @@ -655,8 +655,8 @@ void lapack_csvd_wrapper(cmatrix_t &A, cmatrix_t &U, rvector_t &S, validate_SVdD_result(tempA, U, S, V); // #endif - delete lapackS; - delete work; + delete[] lapackS; + delete[] work; if (info == 0) { return; diff --git a/src/simulators/parallel_state_executor.hpp b/src/simulators/parallel_state_executor.hpp index 030f92456a..0a3b390d35 100644 --- a/src/simulators/parallel_state_executor.hpp +++ b/src/simulators/parallel_state_executor.hpp @@ -64,7 +64,7 @@ class ParallelStateExecutor : public virtual MultiStateExecutor { protected: void set_config(const Config &config) override; - virtual uint_t qubit_scale(void) { return 1; } + virtual uint_t qubit_scale(void) override { return 1; } bool multiple_chunk_required(const Config &config, const Circuit &circuit, const Noise::NoiseModel &noise) const; diff --git a/src/simulators/statevector/statevector_state.hpp b/src/simulators/statevector/statevector_state.hpp index 7ea03ebdd3..8b7c2beb71 100755 --- a/src/simulators/statevector/statevector_state.hpp +++ b/src/simulators/statevector/statevector_state.hpp @@ -213,7 +213,7 @@ class State : public QuantumState::State { cmatrix_t density_matrix(const reg_t &qubits); // Apply the global phase - void apply_global_phase(); + void apply_global_phase() override; protected: //----------------------------------------------------------------------- diff --git a/src/simulators/superoperator/superoperator.hpp b/src/simulators/superoperator/superoperator.hpp index 54343ad932..d36878fd47 100644 --- a/src/simulators/superoperator/superoperator.hpp +++ b/src/simulators/superoperator/superoperator.hpp @@ -53,7 +53,7 @@ class Superoperator : public DensityMatrix { //----------------------------------------------------------------------- // Set the size of the vector in terms of qubit number - void set_num_qubits(size_t num_qubits); + void set_num_qubits(size_t num_qubits) override; // Returns the number of qubits for the superoperator virtual uint_t num_qubits() const override { return num_qubits_; } diff --git a/src/simulators/tensor_network/tensor_net_state.hpp b/src/simulators/tensor_network/tensor_net_state.hpp index 37138420c6..c4a1bb9d62 100644 --- a/src/simulators/tensor_network/tensor_net_state.hpp +++ b/src/simulators/tensor_network/tensor_net_state.hpp @@ -151,7 +151,9 @@ class State : public QuantumState::State { auto move_to_vector(); auto copy_to_vector(); - void enable_density_matrix(bool flg) { enable_density_matrix_ = flg; } + void enable_density_matrix(bool flg) override { + enable_density_matrix_ = flg; + } protected: //----------------------------------------------------------------------- @@ -208,7 +210,7 @@ class State : public QuantumState::State { RngEngine &rng); // Apply the global phase - void apply_global_phase(void); + void apply_global_phase(void) override; //----------------------------------------------------------------------- // Save data instructions diff --git a/src/simulators/unitary/unitary_state.hpp b/src/simulators/unitary/unitary_state.hpp index 11b6700133..968c6ed71d 100755 --- a/src/simulators/unitary/unitary_state.hpp +++ b/src/simulators/unitary/unitary_state.hpp @@ -140,7 +140,7 @@ class State : public virtual QuantumState::State { auto copy_to_matrix(); // Apply the global phase - void apply_global_phase(); + void apply_global_phase() override; protected: //----------------------------------------------------------------------- diff --git a/src/transpile/fusion.hpp b/src/transpile/fusion.hpp index 9948c640dc..10dbccaeae 100644 --- a/src/transpile/fusion.hpp +++ b/src/transpile/fusion.hpp @@ -173,7 +173,8 @@ class UnitaryFusion : public FusionMethod { std::string("fusion")); }; - virtual bool can_apply(const op_t &op, uint_t max_fused_qubits) const { + virtual bool can_apply(const op_t &op, + uint_t max_fused_qubits) const override { if (op.conditional || op.sample_noise) return false; switch (op.type) { @@ -220,7 +221,8 @@ class SuperOpFusion : public UnitaryFusion { return Operations::make_superop(qubits, std::move(superop)); }; - virtual bool can_apply(const op_t &op, uint_t max_fused_qubits) const { + virtual bool can_apply(const op_t &op, + uint_t max_fused_qubits) const override { if (op.conditional || op.sample_noise) return false; switch (op.type) { @@ -270,7 +272,8 @@ class KrausFusion : public UnitaryFusion { return Operations::make_kraus(qubits, Utils::superop2kraus(superop, dim)); }; - virtual bool can_apply(const op_t &op, uint_t max_fused_qubits) const { + virtual bool can_apply(const op_t &op, + uint_t max_fused_qubits) const override { if (op.conditional || op.sample_noise) return false; switch (op.type) { @@ -346,7 +349,7 @@ void Fuser::allocate_new_operation(oplist_t &ops, const uint_t idx, ops[i].type = optype_t::nop; } -class CostBasedFusion : public Fuser { +class CostBasedFusion final : public Fuser { public: CostBasedFusion() { std::fill_n(costs_, 64, -1); }; @@ -377,7 +380,7 @@ class CostBasedFusion : public Fuser { }; template -class NQubitFusion : public Fuser { +class NQubitFusion final : public Fuser { public: NQubitFusion() : opt_name(std::to_string(N) + "_qubits") {}