From 8aeadf083bc25a30c7dfb608895242e4bb02a9f7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 17 Mar 2004 20:13:20 +0000 Subject: [PATCH] backport: c-typeck.c (pedantic_lvalue_warning): Deprecate compound expressions as lvalues. Backport: 2003-11-08 Joseph S. Myers * c-typeck.c (pedantic_lvalue_warning): Deprecate compound expressions as lvalues. * doc/extend.texi: Document that all extended lvalues are now deprecated. 2003-11-05 Joseph S. Myers * c-typeck.c (pedantic_lvalue_warning): Deprecate use of conditional expressions as lvalues. 2003-10-22 Joseph S. Myers * c-typeck.c (pedantic_lvalue_warning): Unconditionally warn of deprecation of casts as lvalues. * fixinc/inclhack.def (obstack_lvalue_cast): New fix. * fixinc/fixincl.x: Regenerate. From-SVN: r79600 --- gcc/ChangeLog | 22 +++++++++++++++++++ gcc/c-typeck.c | 25 +++++++++++----------- gcc/doc/extend.texi | 4 +--- gcc/fixinc/fixincl.x | 47 ++++++++++++++++++++++++++++++++++++++--- gcc/fixinc/inclhack.def | 25 ++++++++++++++++++++++ 5 files changed, 104 insertions(+), 19 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index af99edc81d5d..431df9b51cf2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,25 @@ +2004-03-17 Ian Lance Taylor + + Backport: + 2003-11-08 Joseph S. Myers + + * c-typeck.c (pedantic_lvalue_warning): Deprecate compound + expressions as lvalues. + * doc/extend.texi: Document that all extended lvalues are now + deprecated. + + 2003-11-05 Joseph S. Myers + + * c-typeck.c (pedantic_lvalue_warning): Deprecate use of + conditional expressions as lvalues. + + 2003-10-22 Joseph S. Myers + + * c-typeck.c (pedantic_lvalue_warning): Unconditionally warn of + deprecation of casts as lvalues. + * fixinc/inclhack.def (obstack_lvalue_cast): New fix. + * fixinc/fixincl.x: Regenerate. + 2004-03-15 Richard Henderson PR middle-end/14535 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index e50ce5b100ae..a3ef0f69fb59 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3234,19 +3234,18 @@ static void pedantic_lvalue_warning (code) enum tree_code code; { - if (pedantic) - switch (code) - { - case COND_EXPR: - pedwarn ("ISO C forbids use of conditional expressions as lvalues"); - break; - case COMPOUND_EXPR: - pedwarn ("ISO C forbids use of compound expressions as lvalues"); - break; - default: - pedwarn ("ISO C forbids use of cast expressions as lvalues"); - break; - } + switch (code) + { + case COND_EXPR: + pedwarn ("use of conditional expressions as lvalues is deprecated"); + break; + case COMPOUND_EXPR: + pedwarn ("use of compound expressions as lvalues is deprecated"); + break; + default: + pedwarn ("use of cast expressions as lvalues is deprecated"); + break; + } } /* Warn about storing in something that is `const'. */ diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index f4fd28ea8e32..5d7479e50d2f 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -1037,9 +1037,7 @@ Compound expressions, conditional expressions and casts are allowed as lvalues provided their operands are lvalues. This means that you can take their addresses or store values into them. -Standard C++ allows compound expressions and conditional expressions as -lvalues, and permits casts to reference type, so use of this extension -is deprecated for C++ code. +All these extensions are deprecated. For example, a compound expression can be assigned, provided the last expression in the sequence is an lvalue. These two expressions are diff --git a/gcc/fixinc/fixincl.x b/gcc/fixinc/fixincl.x index 0f20f3a5806b..c2d27b0414b5 100644 --- a/gcc/fixinc/fixincl.x +++ b/gcc/fixinc/fixincl.x @@ -5,7 +5,7 @@ * files which are fixed to work correctly with ANSI C and placed in a * directory that GNU C will search. * - * This file contains 163 fixup descriptions. + * This file contains 164 fixup descriptions. * * See README for more information. * @@ -3806,6 +3806,41 @@ static const char* apzNodeent_SyntaxPatch[] = { "%0;", (char*)NULL }; +/* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Obstack_Lvalue_Cast fix + */ +tSCC zObstack_Lvalue_CastName[] = + "obstack_lvalue_cast"; + +/* + * File name selection pattern + */ +tSCC zObstack_Lvalue_CastList[] = + "|obstack.h|"; +/* + * Machine/OS name selection pattern + */ +#define apzObstack_Lvalue_CastMachs (const char**)NULL + +/* + * content selection pattern - do fix if pattern found + */ +tSCC zObstack_Lvalue_CastSelect0[] = + "\\*\\(\\(([^()]*)\\*\\)(.*)\\)\\+\\+ = \\(([^()]*)\\)"; + +#define OBSTACK_LVALUE_CAST_TEST_CT 1 +static tTestDesc aObstack_Lvalue_CastTests[] = { + { TT_EGREP, zObstack_Lvalue_CastSelect0, (regex_t*)NULL }, }; + +/* + * Fix Command Arguments for Obstack_Lvalue_Cast + */ +static const char* apzObstack_Lvalue_CastPatch[] = { + "format", + "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))", + (char*)NULL }; + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * Description of Osf_Namespace_A fix @@ -6418,9 +6453,9 @@ static const char* apzX11_SprintfPatch[] = { * * List of all fixes */ -#define REGEX_COUNT 177 +#define REGEX_COUNT 178 #define MACH_LIST_SIZE_LIMIT 334 -#define FIX_COUNT 163 +#define FIX_COUNT 164 /* * Enumerate the fixes @@ -6521,6 +6556,7 @@ typedef enum { NEXT_VOLITILE_FIXIDX, NEXT_WAIT_UNION_FIXIDX, NODEENT_SYNTAX_FIXIDX, + OBSTACK_LVALUE_CAST_FIXIDX, OSF_NAMESPACE_A_FIXIDX, OSF_NAMESPACE_C_FIXIDX, PTHREAD_PAGE_SIZE_FIXIDX, @@ -7067,6 +7103,11 @@ tFixDesc fixDescList[ FIX_COUNT ] = { NODEENT_SYNTAX_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, aNodeent_SyntaxTests, apzNodeent_SyntaxPatch, 0 }, + { zObstack_Lvalue_CastName, zObstack_Lvalue_CastList, + apzObstack_Lvalue_CastMachs, + OBSTACK_LVALUE_CAST_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, + aObstack_Lvalue_CastTests, apzObstack_Lvalue_CastPatch, 0 }, + { zOsf_Namespace_AName, zOsf_Namespace_AList, apzOsf_Namespace_AMachs, OSF_NAMESPACE_A_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, diff --git a/gcc/fixinc/inclhack.def b/gcc/fixinc/inclhack.def index 676463e24be7..959cb569da0b 100644 --- a/gcc/fixinc/inclhack.def +++ b/gcc/fixinc/inclhack.def @@ -2131,6 +2131,31 @@ fix = { }; +/* + * 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 -- 2.47.2