Commit 9aa8a1df by Neil Booth Committed by Neil Booth

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
parent 0afeef64
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.
......
......@@ -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,
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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
......
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.
......
/* 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. */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment