__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
+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.
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,
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,
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;
}
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.
--- /dev/null
+/* 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. */
+}