OSDN Git Service

* c-common.c (combine_strings): Complain if concatenating
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Dec 2001 19:42:34 +0000 (19:42 +0000)
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Dec 2001 19:42:34 +0000 (19:42 +0000)
__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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@47890 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-parse.in
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/concat.c [new file with mode: 0644]

index e6a8d64..69959aa 100644 (file)
@@ -1,3 +1,12 @@
+2001-12-11  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * 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.
+
 2001-12-11  Aldy Hernandez  <aldyh@redhat.com>
 
        * c-common.c (type_for_mode): Handle unsigned vectors.
index ad58594..96f8462 100644 (file)
@@ -544,7 +544,11 @@ combine_strings (strings)
              wide_flag = 1;
            }
          else
-           length += (TREE_STRING_LENGTH (t) - 1);
+           {
+             length += (TREE_STRING_LENGTH (t) - 1);
+             if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
+               warning ("concatenation of string literals with __FUNCTION__ is deprecated.  This feature will be removed in future"); 
+           }
        }
 
       /* If anything is wide, the non-wides will be converted,
index 59525d5..5ce8923 100644 (file)
@@ -235,6 +235,10 @@ extern tree c_global_trees[CTI_MAX];
    These may be shadowed, and may be referenced from nested functions.  */
 #define C_DECLARED_LABEL_FLAG(label) TREE_LANG_FLAG_1 (label)
 
+/* Flag strings given by __FUNCTION__ and __PRETTY_FUNCTION__ for a
+   warning if they undergo concatenation.  */
+#define C_ARTIFICIAL_STRING_P(NODE) TREE_LANG_FLAG_0 (NODE)
+
 typedef enum c_language_kind
 {
   clk_c,           /* A dialect of C: K&R C, ANSI/ISO C89, C2000,
index 1602b92..4967a09 100644 (file)
@@ -3604,6 +3604,7 @@ end ifobjc
            const char *name = fname_string (rid_code);
          
            yylval.ttype = build_string (strlen (name) + 1, name);
+           C_ARTIFICIAL_STRING_P (yylval.ttype) = 1;
            last_token = CPP_STRING;  /* so yyerror won't choke */
            return STRING;
          }
index 1a4ff58..10524a5 100644 (file)
@@ -4120,8 +4120,9 @@ On the other hand, @samp{#ifdef __FUNCTION__} does not have any special
 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 f6f4f09..99d04fd 100644 (file)
@@ -1,3 +1,7 @@
+2001-12-11  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * gcc.dg/concat.c: New test.
+
 2001-12-11  Stan Shebs  <shebs@apple.com>
 
        * objc/compile: New test directory.
diff --git a/gcc/testsuite/gcc.dg/concat.c b/gcc/testsuite/gcc.dg/concat.c
new file mode 100644 (file)
index 0000000..4f4f8d7
--- /dev/null
@@ -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.  */
+}