Set the cast kind to CK_NoOp for C-style casts that are really const casts. Fixes PR5248.

llvm-svn: 84514
This commit is contained in:
Anders Carlsson 2009-10-19 18:14:28 +00:00
parent 24fcb826bd
commit 027732b5b9
2 changed files with 17 additions and 0 deletions

View File

@ -1113,6 +1113,9 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
unsigned msg = diag::err_bad_cxx_cast_generic;
TryCastResult tcr = TryConstCast(*this, CastExpr, CastTy, /*CStyle*/true,
msg);
if (tcr == TC_Success)
Kind = CastExpr::CK_NoOp;
if (tcr == TC_NotApplicable) {
// ... or if that is not possible, a static_cast, ignoring const, ...
tcr = TryStaticCast(*this, CastExpr, CastTy, /*CStyle*/true, R, msg,

View File

@ -0,0 +1,14 @@
// RUN: clang-cc %s -emit-llvm -o %t
// PR5248
namespace PR5248 {
struct A {
void copyFrom(const A &src);
void addRef(void);
};
void A::copyFrom(const A &src) {
((A &)src).addRef();
}
}