From de55f647ff07469afd22628424ffc289cdc88d94 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 3 Oct 2009 16:30:22 +0000 Subject: [PATCH] Ignore No-op casts when evaluating lvalue expressions. Fixes PR5122. llvm-svn: 83267 --- clang/lib/AST/ExprConstant.cpp | 10 ++++++++++ clang/test/CodeGenCXX/references.cpp | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 2aefae6fd741..94d22998ebbe 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -180,6 +180,16 @@ public: { return Visit(E->getSubExpr()); } APValue VisitChooseExpr(const ChooseExpr *E) { return Visit(E->getChosenSubExpr(Info.Ctx)); } + + APValue VisitCastExpr(CastExpr *E) { + switch (E->getCastKind()) { + default: + return APValue(); + + case CastExpr::CK_NoOp: + return Visit(E->getSubExpr()); + } + } // FIXME: Missing: __real__, __imag__ }; } // end anonymous namespace diff --git a/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp index 6f4c1032efab..c235521d43b1 100644 --- a/clang/test/CodeGenCXX/references.cpp +++ b/clang/test/CodeGenCXX/references.cpp @@ -95,3 +95,8 @@ struct A { void f(A* a) { int b = a->b(); } + +// PR5122 +void *foo = 0; +void * const & kFoo = foo; +