]> granicus.if.org Git - clang/commitdiff
Set the cast kind to CK_NoOp for C-style casts that are really const casts. Fixes...
authorAnders Carlsson <andersca@mac.com>
Mon, 19 Oct 2009 18:14:28 +0000 (18:14 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 19 Oct 2009 18:14:28 +0000 (18:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84514 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCXXCast.cpp
test/CodeGenCXX/casts.cpp [new file with mode: 0644]

index ef1d128f63dae199539f448c72b70e5d8236efb7..c7aaa6fc67f33499a97f77673113d8f429a4765d 100644 (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,
diff --git a/test/CodeGenCXX/casts.cpp b/test/CodeGenCXX/casts.cpp
new file mode 100644 (file)
index 0000000..045f2d4
--- /dev/null
@@ -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();
+}
+}
+