aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@markmitchell.com>1998-08-19 15:14:58 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1998-08-19 15:14:58 +0000
commit898600d5fa876b04ef2e4de7d3f9f83fd85cf3aa (patch)
treea8e8e350b77e108b758cfb2cd7b897d48d0d05bd /gcc
parenta255ef043cf7c8f5e1174006b240e5d73b6242c9 (diff)
downloadgcc-898600d5fa876b04ef2e4de7d3f9f83fd85cf3aa.zip
gcc-898600d5fa876b04ef2e4de7d3f9f83fd85cf3aa.tar.gz
gcc-898600d5fa876b04ef2e4de7d3f9f83fd85cf3aa.tar.bz2
cp-tree.h (ansi_null_node): New variable.
* cp-tree.h (ansi_null_node): New variable. * decl.c (ansi_null_node): New variable. (init_decl_processing): Initialize its type. * lex.c (init_parse): Initialize its value. Use ansi_null_node for null_node in non-ANSI mode. * typeck.c (build_binary_op_nodefault): Use ansi_null_node in place of null_node to avoid spurious errors. From-SVN: r21858
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/decl.c13
-rw-r--r--gcc/cp/lex.c10
-rw-r--r--gcc/cp/typeck.c9
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/null1.C12
6 files changed, 49 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a1dc384..65e8eb8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+1998-08-19 Mark Mitchell <mark@markmitchell.com>
+
+ * cp-tree.h (ansi_null_node): New variable.
+ * decl.c (ansi_null_node): New variable.
+ (init_decl_processing): Initialize its type.
+ * lex.c (init_parse): Initialize its value. Use ansi_null_node
+ for null_node in non-ANSI mode.
+ * typeck.c (build_binary_op_nodefault): Use ansi_null_node in
+ place of null_node to avoid spurious errors.
+
1998-08-17 Mark Mitchell <mark@markmitchell.com>
* cp-tree.h (enter_scope_of): New function.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 5fe07cb..f96af15 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1918,6 +1918,7 @@ extern tree long_long_integer_type_node, long_long_unsigned_type_node;
extern tree integer_two_node, integer_three_node;
extern tree boolean_type_node, boolean_true_node, boolean_false_node;
+extern tree ansi_null_node;
extern tree null_node;
/* in pt.c */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index e46de42..5e6efa4 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -429,9 +429,13 @@ tree static_aggregates;
tree integer_zero_node;
tree null_pointer_node;
-/* The value for __null (NULL), either of type `void *' or, with -ansi,
- an integer type of the same size. */
+/* The value for __null (NULL), when -ansi is specified. As per the
+ standard, this is an implementation-defined null pointer constant. */
+tree ansi_null_node;
+/* The value for __null (NULL). With -ansi, this is just
+ ansi_null_node. Without -ansi, this is a zero-valued pointer
+ constant of type `{unknown type}*'. */
tree null_node;
/* A node for the integer constants 1, 2, and 3. */
@@ -6030,9 +6034,8 @@ init_decl_processing ()
/* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
TREE_TYPE (unknown_type_node) = unknown_type_node;
- if (flag_ansi)
- TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0);
- else
+ TREE_TYPE (ansi_null_node) = type_for_size (POINTER_SIZE, 0);
+ if (!flag_ansi)
TREE_TYPE (null_node) = build_pointer_type (unknown_type_node);
/* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 2aae5b9..998817b 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -777,7 +777,15 @@ init_parse (filename)
TREE_TYPE (signature_type_node) = signature_type_node;
ridpointers[(int) RID_SIGNATURE] = signature_type_node;
- null_node = build_int_2 (0, 0);
+ /* Create the built-in __null node. Note that we can't yet call for
+ type_for_size here because integer_type_node and so forth are not
+ set up. Therefore, we don't set the type of these nodes until
+ init_decl_processing. */
+ ansi_null_node = build_int_2 (0, 0);
+ if (flag_ansi)
+ null_node = ansi_null_node;
+ else
+ null_node = build_int_2 (0, 0);
ridpointers[RID_NULL] = null_node;
opname_tab[(int) COMPONENT_REF] = "->";
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 1fa589c..2c5529a 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3244,6 +3244,15 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
/* Nonzero means set RESULT_TYPE to the common type of the args. */
int common = 0;
+ /* Unless -ansi is specified, __null has pointer type. But, then,
+ things like `7 != NULL' result in errors about comparisons
+ between pointers and integers. So, here, we replace __null with
+ an appropriate null pointer constant. */
+ if (orig_op0 == null_node)
+ orig_op0 = ansi_null_node;
+ if (orig_op1 == null_node)
+ orig_op1 = ansi_null_node;
+
/* Apply default conversions. */
if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
|| code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
diff --git a/gcc/testsuite/g++.old-deja/g++.other/null1.C b/gcc/testsuite/g++.old-deja/g++.other/null1.C
new file mode 100644
index 0000000..4bdb048
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/null1.C
@@ -0,0 +1,12 @@
+// Build don't link:
+
+#include <cstddef>
+
+void f()
+{
+ int i;
+ float f;
+
+ i != NULL;
+ f != NULL;
+}