diff --git a/shared/cplusplus/PrettyPrinter.cpp b/shared/cplusplus/PrettyPrinter.cpp index d7570127e327e7b7eb9f5ecf623f64cac7a74b87..6fcd06de380c3d7358fbb97bfde38e98d9e9ca50 100644 --- a/shared/cplusplus/PrettyPrinter.cpp +++ b/shared/cplusplus/PrettyPrinter.cpp @@ -1229,7 +1229,16 @@ bool PrettyPrinter::visit(WhileStatementAST *ast) out << '('; accept(ast->condition); out << ')'; - accept(ast->statement); + out << ' '; + if (ast->statement && ast->statement->asCompoundStatement()) + accept(ast->statement); + else { + indent(); + newline(); + accept(ast->statement); + deindent(); + newline(); + } return false; } diff --git a/tests/manual/cplusplus/tests/t1.cpp b/tests/manual/cplusplus/tests/t1.cpp index 186d9fbea7cf0277c8445fa9c06ac34304b37803..0151673c70bb0dd9847e6136bcebd0539bea4bdb 100644 --- a/tests/manual/cplusplus/tests/t1.cpp +++ b/tests/manual/cplusplus/tests/t1.cpp @@ -20,6 +20,16 @@ class Class { else if (b == 20) return 2; else if (c == 30) { x = 1; } } + + void test_while() { + while (int a = 1) { + exit(); + } + + while (x==1) do_something_here(); + + while (x==2) if(a==1) c(); else if (a==2) c(); else c3(); + } }; class Derived: public Class {