This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

3.0 branch: Deprecate __FUNCTION__ concatenation


OK for 3.0 branch on completion of a successful make check?

Neil.

	* c-common.c (combine_strings): Complain if concatenating
	__FUNCTION__.
	* c-parse.in (yylexname): Flag artificial strings.
	* tree.h (TREE_ARTIFICIAL_STRING_P): New.
doc:
	* extend.texi: Update.
testsuite:
	* gcc.dg/concat.c: New test.

Index: gcc/c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.226.2.6
diff -u -p -r1.226.2.6 c-common.c
--- c-common.c	2001/11/05 19:10:31	1.226.2.6
+++ c-common.c	2001/12/10 21:08:01
@@ -401,7 +401,11 @@ combine_strings (strings)
 	      wide_flag = 1;
 	    }
 	  else
-	    length += (TREE_STRING_LENGTH (t) - 1);
+	    {
+	      length += (TREE_STRING_LENGTH (t) - 1);
+	      if (TREE_ARTIFICIAL_STRING_P (t) && !in_system_header)
+		warning ("concatenation of string literals with __FUNCTION__ is deprecated.  This feature will be removed in GCC 3.2"); 
+	    }
 	}
 
       /* If anything is wide, the non-wides will be converted,
Index: gcc/c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.82.2.2
diff -u -p -r1.82.2.2 c-parse.in
--- c-parse.in	2001/03/07 01:19:55	1.82.2.2
+++ c-parse.in	2001/12/10 21:08:09
@@ -3251,6 +3251,7 @@ yylexname ()
 	     if we put something in the TREE_CHAIN of this one.  */
 	  yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
 				       TREE_STRING_POINTER (stringval));
+	  TREE_ARTIFICIAL_STRING_P (yylval.ttype) = 1;
 	  return STRING;
 	}
     }
Index: gcc/tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.223.2.13
diff -u -p -r1.223.2.13 tree.h
--- tree.h	2001/07/11 16:57:31	1.223.2.13
+++ tree.h	2001/12/10 21:08:18
@@ -207,6 +207,8 @@ struct tree_common
            TREE_LIST
        TREE_PROTECTED in
            BLOCK
+       TREE_ARTIFICIAL_STRING_P in
+           STRING_CST
 	   ??? unspecified nodes
 
    side_effects_flag:
@@ -705,6 +707,11 @@ struct tree_real_cst
 /* In a STRING_CST */
 #define TREE_STRING_LENGTH(NODE) (STRING_CST_CHECK (NODE)->string.length)
 #define TREE_STRING_POINTER(NODE) (STRING_CST_CHECK (NODE)->string.pointer)
+
+/* Flag strings given by __FUNCTION__ and __PRETTY_FUNCTION__ for a
+   warning if they undergo concatenation.  */
+#define TREE_ARTIFICIAL_STRING_P(NODE) \
+	(STRING_CST_CHECK(NODE)->common.protected_flag)
 
 struct tree_string
 {
Index: gcc/doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 extend.texi
--- extend.texi	2001/11/03 13:26:57	1.1.2.17
+++ extend.texi	2001/12/10 21:08:34
@@ -3648,8 +3648,8 @@ __PRETTY_FUNCTION__ = int  a::sub (int)
 The compiler automagically replaces the identifiers with a string
 literal containing the appropriate name.  Thus, they are neither
 preprocessor macros, like @code{__FILE__} and @code{__LINE__}, nor
-variables.  This means that they catenate with other string literals, and
-that they can be used to initialize char arrays.  For example
+variables.  This means that they catenate with other string literals,
+and that they can be used to initialize char arrays.  For example
 
 @smallexample
 char here[] = "Function " __FUNCTION__ " in " __FILE__;
@@ -3659,8 +3659,9 @@ On the other hand, @samp{#ifdef __FUNCTI
 meaning inside a function, since the preprocessor does not do anything
 special with the identifier @code{__FUNCTION__}.
 
-GCC also supports the magic word @code{__func__}, defined by the
-ISO standard C99:
+Note that these semantics are deprecated, and that GCC 3.2 will handle
+@code{__FUNCTION__} and @code{__PRETTY_FUNCTION__} the same way as
+@code{__func__}.  @code{__func__} is defined by the ISO standard C99:
 
 @display
 The identifier @code{__func__} is implicitly declared by the translator
Index: gcc/testsuite/gcc.dg/concat.c
===================================================================
RCS file: concat.c
diff -N concat.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ concat.c	Mon Dec 10 13:08:34 2001
@@ -0,0 +1,16 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.  */
+
+/* { dg-do compile } */
+
+/* Test we output a warning for concatenation of artifical strings.
+
+   Neil Booth, 10 Dec 2001.  */
+
+void foo ()
+{
+  char str1[] = __FUNCTION__ ".";	/* { dg-warning "deprecated" } */
+  char str2[] = __PRETTY_FUNCTION__ ".";/* { dg-warning "deprecated" } */
+  char str3[] = "." __FUNCTION__;	/* { dg-warning "deprecated" } */
+  char str4[] = "." __PRETTY_FUNCTION__;/* { dg-warning "deprecated" } */
+  char str5[] = "." ".";	/* No warning.  */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]