mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 08:51:04 +01:00
Fix infinite recursion in PrintList. (#642)
Also make `Stack`'s single-argument constructor explicit, which would have helped catch this at compile time.
This commit is contained in:
@@ -102,7 +102,7 @@ void Action::Print(std::ostream& out) {
|
||||
|
||||
void Action::PrintList(Stack<Action*> ls, std::ostream& out) {
|
||||
if (!ls.IsEmpty()) {
|
||||
PrintList(ls.Pop(), out);
|
||||
ls.Pop()->Print(out);
|
||||
if (!ls.IsEmpty()) {
|
||||
out << " :: ";
|
||||
PrintList(ls, out);
|
||||
|
||||
@@ -57,7 +57,7 @@ struct Stack {
|
||||
Stack() { head = nullptr; }
|
||||
|
||||
// Creates an instance containing just `x`.
|
||||
Stack(T x) : Stack() { Push(x); }
|
||||
explicit Stack(T x) : Stack() { Push(x); }
|
||||
|
||||
// Pushes `x` onto the top of the stack.
|
||||
void Push(T x) { head = new ListNode<T>(x, head); }
|
||||
|
||||
Reference in New Issue
Block a user