Skip to content

Commit

Permalink
Merge pull request #3815 from hzeller/20230829-no-implicit-conversion
Browse files Browse the repository at this point in the history
Make sure C++ compiler does not generate unexpected implicit conversi…
  • Loading branch information
alaindargelas authored Aug 29, 2023
2 parents 61cbbe1 + 25549fd commit fa0a08c
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/bin/run-clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Checks: >
clang-diagnostic-overloaded-virtual
clang-diagnostic-unused-private-field,
google-build-using-namespace,
google-explicit-constructor,
modernize-loop-convert,
modernize-raw-string-literal,
modernize-use-override,
Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Common/NodeId.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class NodeId final {
constexpr explicit NodeId(RawNodeId id) : id(id) {}
constexpr NodeId(const NodeId &rhs) : id(rhs.id) {}

operator RawNodeId() const { return id; }
operator RawNodeId() const { return id; } // NOLINT

// Don't include size_t conversion on 32Bit machines where sizeof(size_t)==32
template <typename T = std::size_t,
typename std::enable_if<!std::is_same<T, RawNodeId>::value>::type
* = nullptr>
operator std::size_t() const {
operator std::size_t() const { // NOLINT
return id;
}

Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/Common/PathId.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ inline std::ostream &operator<<(std::ostream &strm, const PathId &pathId) {
struct PathIdPP final { // Pretty Printer
const PathId &m_id;

PathIdPP(const PathId &id) : m_id(id) {}
explicit PathIdPP(const PathId &id) : m_id(id) {}
};

std::ostream &operator<<(std::ostream &strm, const PathIdPP &id);
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/Common/PlatformFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ class PlatformFileSystem : public FileSystem {
T *ptr = nullptr;
Helper() : ptr(nullptr) {}
Helper(Helper const &) = default;
Helper(T *p) : ptr(p) {}
Helper(T *p) : ptr(p) {} // NOLINT
template <class U>
Helper(std::shared_ptr<U> const &sp) : ptr(sp.get()) {}
Helper(std::shared_ptr<U> const &sp) : ptr(sp.get()) {} // NOLINT
template <class U, class... Ts>
Helper(std::unique_ptr<U, Ts...> const &up) : ptr(up.get()) {}
Helper(std::unique_ptr<U, Ts...> const &up) : ptr(up.get()) {} // NOLINT
// && optional: enforces rvalue use only
bool operator<(const Helper &o) const {
return std::less<T *>()(ptr, o.ptr);
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/Design/DefParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Value;

class DefParam final {
public:
DefParam(std::string_view name, DefParam* parent = nullptr)
explicit DefParam(std::string_view name, DefParam* parent = nullptr)
: m_name(name),
m_value(nullptr),
m_used(false),
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/Design/Netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ModPort;

class Netlist {
public:
Netlist(ModuleInstance* parent) : m_parent(parent) {}
explicit Netlist(ModuleInstance* parent) : m_parent(parent) {}
~Netlist();

typedef std::map<std::string, std::pair<ModPort*, UHDM::modport*>,
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/CompileDesign.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void decompile(ValuedComponentI* instance);
class CompileDesign {
public:
// Note: takes owernship of compiler
CompileDesign(Compiler* compiler);
explicit CompileDesign(Compiler* compiler);
virtual ~CompileDesign(); // Used in MockCompileDesign

bool compile();
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/DesignElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ModuleInstanceFactory;

class DesignElaboration : public TestbenchElaboration {
public:
DesignElaboration(CompileDesign* compileDesign);
explicit DesignElaboration(CompileDesign* compileDesign);
DesignElaboration(const DesignElaboration& orig) = delete;
~DesignElaboration() override;

Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/ElaborationStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Variable;

class ElaborationStep {
public:
ElaborationStep(CompileDesign* compileDesign);
explicit ElaborationStep(CompileDesign* compileDesign);
ElaborationStep(const ElaborationStep& orig) = delete;

virtual bool elaborate() = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/NetlistElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Signal;

class NetlistElaboration : public TestbenchElaboration {
public:
NetlistElaboration(CompileDesign* compileDesign);
explicit NetlistElaboration(CompileDesign* compileDesign);
NetlistElaboration(const NetlistElaboration& orig) = delete;

bool elaborate() override;
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/PackageAndRootElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace SURELOG {

class PackageAndRootElaboration : public ElaborationStep {
public:
PackageAndRootElaboration(CompileDesign* compileDesign)
explicit PackageAndRootElaboration(CompileDesign* compileDesign)
: ElaborationStep(compileDesign) {}

~PackageAndRootElaboration() override = default;
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/TestbenchElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Variable;

class TestbenchElaboration : public ElaborationStep {
public:
TestbenchElaboration(CompileDesign* compileDesign)
explicit TestbenchElaboration(CompileDesign* compileDesign)
: ElaborationStep(compileDesign) {}

TestbenchElaboration(const TestbenchElaboration& orig);
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/DesignCompile/UVMElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CompileDesign;

class UVMElaboration : public TestbenchElaboration {
public:
UVMElaboration(CompileDesign* compileDesign);
explicit UVMElaboration(CompileDesign* compileDesign);
UVMElaboration(const UVMElaboration& orig) = delete;
~UVMElaboration() override = default;

Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/Expression/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ class SValue final : public Value {
m_signed(true) {
m_value.s_int = val;
}
SValue(uint64_t val)
explicit SValue(uint64_t val)
: m_type(Value::Type::Unsigned), m_size(64), m_valid(1), m_negative(0) {
m_value.u_int = val;
}
SValue(int64_t val)
explicit SValue(int64_t val)
: m_type(Value::Type::Integer),
m_size(64),
m_valid(1),
m_negative(val < 0),
m_signed(true) {
m_value.s_int = val;
}
SValue(double val)
explicit SValue(double val)
: m_type(Value::Type::Double),
m_size(64),
m_valid(1),
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/Library/AntlrLibParserErrorListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ParseLibraryDef;

class AntlrLibParserErrorListener : public antlr4::ANTLRErrorListener {
public:
AntlrLibParserErrorListener(ParseLibraryDef *parser) : m_parser(parser) {}
explicit AntlrLibParserErrorListener(ParseLibraryDef *parser) : m_parser(parser) {}

~AntlrLibParserErrorListener() override{};

Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/SourceCompile/CheckCompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Compiler;

class CheckCompile {
public:
CheckCompile(Compiler* compiler) : m_compiler(compiler) {}
explicit CheckCompile(Compiler* compiler) : m_compiler(compiler) {}
bool check();
virtual ~CheckCompile() = default;

Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/SourceCompile/CompilationUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MacroInfo;

class CompilationUnit {
public:
CompilationUnit(bool fileunit);
explicit CompilationUnit(bool fileunit);
CompilationUnit(const CompilationUnit& orig) = delete;
virtual ~CompilationUnit() = default;

Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/SourceCompile/LoopCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LoopCheck {

class Node {
public:
Node(SymbolId objId) : m_objId(objId), m_visited(false) {}
explicit Node(SymbolId objId) : m_objId(objId), m_visited(false) {}
const SymbolId m_objId;
std::set<Node*> m_toList;
bool m_visited;
Expand Down

0 comments on commit fa0a08c

Please sign in to comment.