This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: fixinc Patch to deprecate casts as lvalues for C
On Mon, 20 Oct 2003, Bruce Korb wrote:
> * because ``*((TYPE*)PTRVAR1)'' is not always legal l-value.
The non-lvalue is (given precedence) actually ((TYPE*)PTRVAR1). The
obstack.h code is confusing! How about the following fixinc patch with
what I hope is an accurate comment?
2003-10-20 Joseph S. Myers <jsm@polyomino.org.uk>
* fixinc/inclhack.def (obstack_lvalue_cast): New fix.
* fixinc/fixincl.x: Regenerate.
* fixinc/tests/base/obstack.h: New test.
--- GCC/gcc/fixinc/inclhack.def.orig 2003-10-15 08:05:56.000000000 +0000
+++ GCC/gcc/fixinc/inclhack.def 2003-10-20 21:24:45.000000000 +0000
@@ -1978,6 +1978,31 @@
/*
+ * obstack.h used casts as lvalues.
+ *
+ * We need to change postincrements of casted pointers (which are
+ * then dereferenced and assigned into) of the form
+ *
+ * *((TYPE*)PTRVAR)++ = (VALUE)
+ *
+ * into expressions like
+ *
+ * ((*((TYPE*)PTRVAR) = (VALUE)), (PTRVAR += sizeof (TYPE)))
+ *
+ * which is correct for the cases used in obstack.h since PTRVAR is
+ * of type char * and the value of the expression is not used.
+ */
+fix = {
+ hackname = obstack_lvalue_cast;
+ files = obstack.h;
+ select = '\*\(\(([^()]*)\*\)(.*)\)\+\+ = \(([^()]*)\)';
+ c_fix = format;
+ c_fix_arg = "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))";
+ test_text = "*((void **) (h)->next_free)++ = (aptr)";
+};
+
+
+/*
* sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
* defining regex.h related types. This causes libg++ build and usage
* failures. Fixing this correctly requires checking and modifying 3 files.
--- GCC/gcc/fixinc/tests/base/obstack.h 2002-08-26 16:21:36.000000000 +0000
+++ GCC/gcc/fixinc/tests/base/obstack.h 2003-10-20 20:00:25.000000000 +0000
@@ -0,0 +1,14 @@
+/* DO NOT EDIT THIS FILE.
+
+ It has been auto-edited by fixincludes from:
+
+ "fixinc/tests/inc/obstack.h"
+
+ This had to be done to correct non-standard usages in the
+ original, manufacturer supplied header file. */
+
+
+
+#if defined( OBSTACK_LVALUE_CAST_CHECK )
+((*((void **) (h)->next_free) = (aptr)), ( (h)->next_free += sizeof (void *)))
+#endif /* OBSTACK_LVALUE_CAST_CHECK */
--
Joseph S. Myers
jsm@polyomino.org.uk