@@ -430,10 +430,10 @@ convert_expr (tree exp, Type *etype, Type *totype)
/* d_convert will make a no-op cast. */
break;
}
- else if (cdfrom->isCPPclass ())
+ else if (cdfrom->isCPPclass () || cdto->isCPPclass ())
{
/* Downcasting in C++ is a no-op. */
- if (cdto->isCPPclass ())
+ if (cdfrom->isCPPclass () && cdto->isCPPclass ())
break;
/* Casting from a C++ interface to a class/non-C++ interface
new file mode 100644
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "-Waddress" }
+
+void* ptr;
+
+int test()
+{
+ if (&ptr) // { dg-warning "the address of 'ptr' will always evaluate as 'true'" }
+ return 1;
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// { dg-options "-Wcast-result" }
+
+extern(C++) class CPPClass
+{
+ int a;
+}
+
+extern(D) class DClass
+{
+ int a;
+}
+
+void test()
+{
+ auto cpptod = cast(DClass)new CPPClass; // { dg-warning "cast to 'Wcastresult1.DClass' will produce null result" }
+ auto dtocpp = cast(CPPClass)new DClass; // { dg-warning "cast to 'Wcastresult1.CPPClass' will produce null result" }
+}
new file mode 100644
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "-Wcast-result" }
+
+void test()
+{
+ auto imvalue = 1.23i;
+ auto revalue = 1.23;
+
+ auto imtore = cast(double)imvalue; // { dg-warning "cast from 'idouble' to 'double' will produce zero result" }
+ auto retoim = cast(idouble)revalue; // { dg-warning "cast from 'double' to 'idouble' will produce zero result" }
+ return;
+}