diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2001-12-11 19:42:34 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2001-12-11 19:42:34 +0000 |
commit | 9aa8a1df0506a9622fea14f7c28b73fdd5324f8e (patch) | |
tree | 2018e6f82b3ca5d8eb854a0d321eb3e9f7091dea /gcc | |
parent | 0afeef64be52defd45b00c47464183dd43381725 (diff) | |
download | gcc-9aa8a1df0506a9622fea14f7c28b73fdd5324f8e.zip gcc-9aa8a1df0506a9622fea14f7c28b73fdd5324f8e.tar.gz gcc-9aa8a1df0506a9622fea14f7c28b73fdd5324f8e.tar.bz2 |
c-common.c (combine_strings): Complain if concatenating __FUNCTION__.
* 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.
From-SVN: r47890
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/c-common.c | 6 | ||||
-rw-r--r-- | gcc/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-parse.in | 1 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/concat.c | 16 |
7 files changed, 42 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e6a8d64..69959aa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/c-common.c b/gcc/c-common.c index ad58594..96f8462 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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, diff --git a/gcc/c-common.h b/gcc/c-common.h index 59525d5..5ce8923 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -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, diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 1602b92..4967a09 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -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; } diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 1a4ff58..10524a5 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f6f4f09..99d04fd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..4f4f8d7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/concat.c @@ -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. */ +} |