Fix #74934.
* expression.cs (BinaryResolveOperator): If one of the operands of
an equality comparison is 'null' and the other is a pointer type,
convert the null to a NullPointer.
* convert.cs (ImplicitReferenceConversion): If the expression is a
NullLiteral and the target type is a pointer type, return a
NullPointer instead.
(ImplicitConversionStandard): Likewise.
In tests:
* test-380.cs: New test from #74934.
svn path=/trunk/mcs/; revision=44495
+2005-05-13 Raja R Harinath <rharinath@novell.com>
+
+ Fix #74934.
+ * expression.cs (BinaryResolveOperator): If one of the operands of
+ an equality comparison is 'null' and the other is a pointer type,
+ convert the null to a NullPointer.
+ * convert.cs (ImplicitReferenceConversion): If the expression is a
+ NullLiteral and the target type is a pointer type, return a
+ NullPointer instead.
+ (ImplicitConversionStandard): Likewise.
+
2005-05-13 Marek Safar <marek.safar@seznam.cz>
* cs-parser.jay: Set readonly context based on special constructs.
// from the null type to any reference-type.
if (expr_type == TypeManager.null_type){
if (target_type.IsPointer)
- return new EmptyCast (expr, target_type);
+ return new EmptyCast (NullPointer.Null, target_type);
if (!target_type.IsValueType)
return new NullCast (expr, target_type);
if (target_type.IsPointer) {
if (expr_type == TypeManager.null_type)
- return new EmptyCast (expr, target_type);
+ return new EmptyCast (NullPointer.Null, target_type);
if (expr_type == TypeManager.void_ptr_type)
return new EmptyCast (expr, target_type);
return this;
}
-
+
// IntPtr equality
if (l == TypeManager.intptr_type && r == TypeManager.intptr_type) {
Type = TypeManager.bool_type;
return this;
}
+ if (l.IsPointer || r.IsPointer) {
+ if (l.IsPointer && r.IsPointer) {
+ type = TypeManager.bool_type;
+ return this;
+ }
+
+ if (l.IsPointer && r == TypeManager.null_type) {
+ right = new EmptyCast (NullPointer.Null, l);
+ type = TypeManager.bool_type;
+ return this;
+ }
+
+ if (r.IsPointer && l == TypeManager.null_type) {
+ left = new EmptyCast (NullPointer.Null, r);
+ type = TypeManager.bool_type;
+ return this;
+ }
+ }
+
//
// operator != (object a, object b)
// operator == (object a, object b)
// Pointer comparison
//
if (l.IsPointer && r.IsPointer){
- if (oper == Operator.Equality || oper == Operator.Inequality ||
- oper == Operator.LessThan || oper == Operator.LessThanOrEqual ||
+ if (oper == Operator.LessThan || oper == Operator.LessThanOrEqual ||
oper == Operator.GreaterThan || oper == Operator.GreaterThanOrEqual){
type = TypeManager.bool_type;
return this;
+2005-05-13 Raja R Harinath <rharinath@novell.com>
+
+ * test-380.cs: New test from #74934.
+
2005-05-12 Raja R Harinath <harinath@gmail.com>
* test-378.cs: New test from #74920.
# He may also move some to TEST_EXCLUDE_net_2_0 if some of the merges are inappropriate for GMCS.
#
NEW_TEST_SOURCES_common = test-336 test-369 cls-test-6 test-294 \
- test-372 test-375 test-376 test-377 test-378 test-360
+ test-372 test-375 test-376 test-377 test-378 test-360 test-380
#
# Please do _not_ add any tests here - all new tests should go into NEW_TEST_SOURCES_common
--- /dev/null
+// Compiler options: -unsafe
+
+class T {
+ static unsafe int Main () {
+ int *a = null;
+ int **b = &a;
+ if (*b == null)
+ return 0;
+ return 1;
+ }
+}