Skip to content

Commit

Permalink
Correct printing of nested anonymous type member accesses.
Browse files Browse the repository at this point in the history
Patch by Florent Bruneau!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167736 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dwblaikie committed Nov 12, 2012
1 parent f634bdf commit 383ec17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/AST/StmtPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,18 @@ void StmtPrinter::VisitCallExpr(CallExpr *Call) {
void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
// FIXME: Suppress printing implicit bases (like "this")
PrintExpr(Node->getBase());

MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
FieldDecl *ParentDecl = ParentMember ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()): NULL;

if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion()) {
OS << (Node->isArrow() ? "->" : ".");
}

if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
if (FD->isAnonymousStructOrUnion())
return;
OS << (Node->isArrow() ? "->" : ".");

if (NestedNameSpecifier *Qualifier = Node->getQualifier())
Qualifier->print(OS, Policy);
if (Node->hasTemplateKeyword())
Expand Down
14 changes: 13 additions & 1 deletion test/Sema/ast-print.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// RUN: %clang_cc1 %s -ast-print
// RUN: %clang_cc1 %s -ast-print | FileCheck %s

typedef void func_typedef();
func_typedef xxx;

typedef void func_t(int x);
func_t a;

struct blah {
struct {
struct {
int b;
};
};
};

int foo(const struct blah *b) {
// CHECK: return b->b;
return b->b;
}

0 comments on commit 383ec17

Please sign in to comment.