[PATCH] D16352: Fix printing of C style casts with suppressed specifiers
Nick Sumner via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 20 04:42:52 PST 2016
nick.sumner created this revision.
nick.sumner added reviewers: bkramer, rsmith.
nick.sumner added a subscriber: cfe-commits.
Allow 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);
http://reviews.llvm.org/D16352
Files:
lib/AST/StmtPrinter.cpp
test/Sema/ast-print.c
Index: test/Sema/ast-print.c
===================================================================
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -53,3 +53,8 @@
// CHECK: struct pair_t p = {a: 3, .b = 4};
struct pair_t p = {a: 3, .b = 4};
+
+void cast() {
+// CHECK: int *x = ((void *)0), *y = ((void *)0);
+ int *x = ((void *)0), *y = ((void *)0);
+}
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp
+++ lib/AST/StmtPrinter.cpp
@@ -1476,7 +1476,9 @@
}
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());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16352.45373.patch
Type: text/x-patch
Size: 846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160120/a17f2515/attachment.bin>
More information about the cfe-commits
mailing list