diff options
author | Anders Carlsson <andersca@mac.com> | 2009-10-19 18:14:28 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-10-19 18:14:28 +0000 |
commit | da921fd19fd496494365f9f2325c338e66216709 (patch) | |
tree | cb68a1bc9d903228b5cb7005c080836ae482c7fb | |
parent | 36c4464ba6cfc2a63dc67c493ef2f5ab2aea09cc (diff) |
Set the cast kind to CK_NoOp for C-style casts that are really const casts. Fixes PR5248.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84514 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaCXXCast.cpp | 3 | ||||
-rw-r--r-- | test/CodeGenCXX/casts.cpp | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index ef1d128f63..c7aaa6fc67 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -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, diff --git a/test/CodeGenCXX/casts.cpp b/test/CodeGenCXX/casts.cpp new file mode 100644 index 0000000000..045f2d4fe0 --- /dev/null +++ b/test/CodeGenCXX/casts.cpp @@ -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(); +} +} + |