Skip to content

Commit 5c27f59

Browse files
committed
Fix non-explicit single-argument constructors
Single-argument constructors must be marked explicit to avoid unintentional implicit conversions.
1 parent 665fb48 commit 5c27f59

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

include/verilogAST.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class NumericLiteral : public Expression {
9292
NumericLiteral(std::string value, unsigned int size)
9393
: value(value), size(size), _signed(false), radix(Radix::DECIMAL){};
9494

95-
NumericLiteral(std::string value)
95+
explicit NumericLiteral(std::string value)
9696
: value(value), size(32), _signed(false), radix(Radix::DECIMAL){};
9797

9898
NumericLiteral(std::string value, Radix radix)
@@ -133,7 +133,7 @@ class Identifier : public Expression {
133133
public:
134134
std::string value;
135135

136-
Identifier(std::string value);
136+
explicit Identifier(std::string value);
137137
Identifier(const Identifier& rhs) : value(rhs.value){};
138138
auto clone() const { return std::unique_ptr<Identifier>(clone_impl()); }
139139

@@ -187,7 +187,7 @@ class String : public Expression {
187187
public:
188188
std::string value;
189189

190-
String(std::string value) : value(value){};
190+
explicit String(std::string value) : value(value){};
191191
String(const String& rhs) : value(rhs.value){};
192192

193193
std::string toString() override;
@@ -386,7 +386,7 @@ class Concat : public Expression {
386386
std::vector<std::unique_ptr<Expression>> args;
387387
bool unpacked;
388388

389-
Concat(std::vector<std::unique_ptr<Expression>> args, bool unpacked = false)
389+
explicit Concat(std::vector<std::unique_ptr<Expression>> args, bool unpacked = false)
390390
: args(std::move(args)), unpacked(unpacked){};
391391
Concat(const Concat& rhs) {
392392
for (const auto& arg : rhs.args) args.push_back(arg->clone());
@@ -420,7 +420,7 @@ class NegEdge : public Node {
420420
public:
421421
std::unique_ptr<Identifier> value;
422422

423-
NegEdge(std::unique_ptr<Identifier> value) : value(std::move(value)){};
423+
explicit NegEdge(std::unique_ptr<Identifier> value) : value(std::move(value)){};
424424
std::string toString() override;
425425
~NegEdge(){};
426426
};
@@ -429,7 +429,7 @@ class PosEdge : public Node {
429429
public:
430430
std::unique_ptr<Identifier> value;
431431

432-
PosEdge(std::unique_ptr<Identifier> value) : value(std::move(value)){};
432+
explicit PosEdge(std::unique_ptr<Identifier> value) : value(std::move(value)){};
433433
std::string toString() override;
434434
~PosEdge(){};
435435
};
@@ -441,7 +441,7 @@ class Call {
441441

442442
Call(std::string func, std::vector<std::unique_ptr<Expression>> args)
443443
: func(func), args(std::move(args)){};
444-
Call(std::string func) : func(func){};
444+
explicit Call(std::string func) : func(func){};
445445
std::string toString();
446446
~Call(){};
447447
};
@@ -459,7 +459,7 @@ class CallExpr : public Expression, public Call {
459459
public:
460460
CallExpr(std::string func, std::vector<std::unique_ptr<Expression>> args)
461461
: Call(std::move(func), std::move(args)){};
462-
CallExpr(std::string func) : Call(std::move(func)){};
462+
explicit CallExpr(std::string func) : Call(std::move(func)){};
463463
CallExpr(const CallExpr& rhs) : Call(std::move(rhs.func)) {
464464
for (const auto& arg : rhs.args) {
465465
args.push_back(arg->clone());
@@ -538,7 +538,7 @@ class Port : public AbstractPort {
538538
Port(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Vector>> value,
539539
Direction direction, PortType data_type)
540540
: value(std::move(value)), direction(direction), data_type(data_type){};
541-
Port(std::unique_ptr<Port> port)
541+
explicit Port(std::unique_ptr<Port> port)
542542
: value(std::move(port->value)),
543543
direction(port->direction),
544544
data_type(port->data_type){};
@@ -550,7 +550,7 @@ class StringPort : public AbstractPort {
550550
public:
551551
std::string value;
552552

553-
StringPort(std::string value) : value(value){};
553+
explicit StringPort(std::string value) : value(value){};
554554
std::string toString() { return value; };
555555
~StringPort(){};
556556
};
@@ -566,7 +566,7 @@ class SingleLineComment : public StructuralStatement,
566566
std::string value;
567567
std::unique_ptr<Statement> statement; // optional
568568

569-
SingleLineComment(std::string value)
569+
explicit SingleLineComment(std::string value)
570570
: value(value), statement(std::unique_ptr<Statement>{}){};
571571
SingleLineComment(std::string value, std::unique_ptr<Statement> statement)
572572
: value(value), statement(std::move(statement)){};
@@ -578,7 +578,7 @@ class BlockComment : public StructuralStatement, public BehavioralStatement {
578578
public:
579579
std::string value;
580580

581-
BlockComment(std::string value) : value(value){};
581+
explicit BlockComment(std::string value) : value(value){};
582582
std::string toString() { return "/*\n" + value + "\n*/"; };
583583
~BlockComment(){};
584584
};
@@ -591,7 +591,7 @@ class InlineVerilog : public StructuralStatement {
591591
public:
592592
std::string value;
593593

594-
InlineVerilog(std::string value) : value(value){};
594+
explicit InlineVerilog(std::string value) : value(value){};
595595
std::string toString() { return value; };
596596
~InlineVerilog(){};
597597
};
@@ -749,7 +749,7 @@ class IfNDef : public IfMacro {
749749

750750
class Wire : public Declaration {
751751
public:
752-
Wire(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Index>,
752+
explicit Wire(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Index>,
753753
std::unique_ptr<Slice>, std::unique_ptr<Vector>>
754754
value)
755755
: Declaration(std::move(value), "wire"){};
@@ -758,7 +758,7 @@ class Wire : public Declaration {
758758

759759
class Reg : public Declaration {
760760
public:
761-
Reg(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Index>,
761+
explicit Reg(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Index>,
762762
std::unique_ptr<Slice>, std::unique_ptr<Vector>>
763763
value)
764764
: Declaration(std::move(value), "reg"){};
@@ -838,7 +838,7 @@ class CallStmt : public BehavioralStatement, public Call {
838838
public:
839839
CallStmt(std::string func, std::vector<std::unique_ptr<Expression>> args)
840840
: Call(std::move(func), std::move(args)){};
841-
CallStmt(std::string func) : Call(std::move(func)){};
841+
explicit CallStmt(std::string func) : Call(std::move(func)){};
842842
std::string toString() { return Call::toString() + ";"; };
843843
};
844844

@@ -959,7 +959,7 @@ class StringModule : public AbstractModule {
959959
public:
960960
std::string definition;
961961

962-
StringModule(std::string definition) : definition(definition){};
962+
explicit StringModule(std::string definition) : definition(definition){};
963963
std::string toString() { return definition; };
964964
~StringModule(){};
965965
};
@@ -968,7 +968,7 @@ class File : public Node {
968968
public:
969969
std::vector<std::unique_ptr<AbstractModule>> modules;
970970

971-
File(std::vector<std::unique_ptr<AbstractModule>>& modules)
971+
explicit File(std::vector<std::unique_ptr<AbstractModule>>& modules)
972972
: modules(std::move(modules)){};
973973
std::string toString() override;
974974
~File(){};

0 commit comments

Comments
 (0)