Hi all,
The attached patch allows C style casts to be printed correctly even
when the incoming PrintingPolicy suppresses specifiers. This can
happen, for instance, when casts occur during the initialization of
variables inside a DeclGroup. Given the code:
void foo() {
int *x = ((void *)0), *y = ((void *)0);
}
The casts are printed as:
int *x = ((void *)0), *y = ((*)0);
Note that the second cast lacks 'void' because specifiers are
suppressed when printing members of the declgroup (after the first).
With the patch, the casts are printed as:
int *x = ((void *)0), *y = ((void *)0);
Best,
Nick
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 305a1c8..46fef8f 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -1287,7 +1287,9 @@ void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
}
void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
OS << '(';
- Node->getTypeAsWritten().print(OS, Policy);
+ PrintingPolicy SubPolicy(Policy);
+ SubPolicy.SuppressSpecifiers = false;
+ Node->getTypeAsWritten().print(OS, SubPolicy);
OS << ')';
PrintExpr(Node->getSubExpr());
}
diff --git a/test/Sema/ast-print.c b/test/Sema/ast-print.c
index e0f86e9..50e0ca8 100644
--- a/test/Sema/ast-print.c
+++ b/test/Sema/ast-print.c
@@ -56,3 +56,8 @@ struct pair_t p = {a: 3, .b = 4};
// CHECK: char c = '\x80';
char c = '\200';
+
+void cast() {
+ // CHECK: int *x = ((void *)0), *y = ((void *)0);
+ int *x = ((void *)0), *y = ((void *)0);
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits