diff options
author | David Blaikie <dblaikie@gmail.com> | 2012-11-12 19:12:12 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2012-11-12 19:12:12 +0000 |
commit | 383ec17ecaac9ac4fce2747640623274a139badf (patch) | |
tree | 7b4aec745dcc69b1f6dd0b0d7e771880f3739f71 | |
parent | f634bdfbf42758f7d49b468df09efa3686f7b699 (diff) |
Correct printing of nested anonymous type member accesses.
Patch by Florent Bruneau!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167736 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 10 | ||||
-rw-r--r-- | test/Sema/ast-print.c | 14 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 57eb1a9518..31a9726e87 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -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()) diff --git a/test/Sema/ast-print.c b/test/Sema/ast-print.c index ff66d35a1b..2066e182c1 100644 --- a/test/Sema/ast-print.c +++ b/test/Sema/ast-print.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -ast-print +// RUN: %clang_cc1 %s -ast-print | FileCheck %s typedef void func_typedef(); func_typedef xxx; @@ -6,3 +6,15 @@ 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; +} |