From: Martin Liska Date: Mon, 2 Sep 2019 07:07:11 +0000 (+0200) Subject: Use cxx_printable_name for __PRETTY_FUNCTION__ in cp_fname_init. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ae0d3f6a593058ab9fd56a34f604852ea2dec79b;p=gcc.git Use cxx_printable_name for __PRETTY_FUNCTION__ in cp_fname_init. 2019-09-02 Martin Liska PR c++/91155 * c-common.c (fname_as_string): Use cxx_printable_name for __PRETTY_FUNCTION__ same as was used before r265711. 2019-09-02 Martin Liska PR c++/91155 * g++.dg/torture/pr91155.C: New test. From-SVN: r275292 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 8b4e75cb78e..1723dda33c5 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2019-09-02 Martin Liska + + PR c++/91155 + * c-common.c (fname_as_string): Use cxx_printable_name for + __PRETTY_FUNCTION__ same as was used before r265711. + 2019-08-28 Marek Polacek Implement P1152R4: Deprecating some uses of volatile. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3497874cb81..6de95cdfe79 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4511,13 +4511,27 @@ cp_fname_init (const char* name, tree *type_p) static tree cp_make_fname_decl (location_t loc, tree id, int type_dep) { - const char *const name = (type_dep && in_template_function () - ? NULL : fname_as_string (type_dep)); + const char * name = NULL; + bool release_name = false; + if (!(type_dep && in_template_function ())) + { + if (current_function_decl == NULL_TREE) + name = "top level"; + else if (type_dep == 1) /* __PRETTY_FUNCTION__ */ + name = cxx_printable_name (current_function_decl, 2); + else if (type_dep == 0) /* __FUNCTION__ */ + { + name = fname_as_string (type_dep); + release_name = true; + } + else + gcc_unreachable (); + } tree type; tree init = cp_fname_init (name, &type); tree decl = build_decl (loc, VAR_DECL, id, type); - if (name) + if (release_name) free (CONST_CAST (char *, name)); /* As we're using pushdecl_with_scope, we must set the context. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 862e55d481c..947a653d1b9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-02 Martin Liska + + PR c++/91155 + * g++.dg/torture/pr91155.C: New test. + 2019-09-01 Marek Polacek PR c++/91129 - wrong error with binary op in template argument. diff --git a/gcc/testsuite/g++.dg/torture/pr91155.C b/gcc/testsuite/g++.dg/torture/pr91155.C new file mode 100644 index 00000000000..04e4f7ab41b --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr91155.C @@ -0,0 +1,18 @@ +/* PR c++/91155. */ + +template< char C > struct dummy {}; + +template< typename T > const char *test() +{ + __builtin_printf ("test: %s\n", __PRETTY_FUNCTION__); + return __PRETTY_FUNCTION__; +} + +int main() +{ + if (__builtin_strcmp ("const char* test() [with T = dummy<\'\\000\'>]", test< dummy< '\0' > > ()) != 0) + {};// __builtin_abort (); + if (__builtin_strcmp ("const char* test() [with T = dummy<\'\\\'\'>]", test< dummy< '\'' > > ()) != 0) + {};// __builtin_abort (); + return 0; +}