* c-common.c (fname_as_string): Use lang_hooks.decl_printable_name
with verbosity 0, instead of DECL_NAME, for human-readable string.
* g++.dg/ext/fnname1.C: New test. (__func__ for C++.)
* g++.dg/ext/fnname2.C: Likewise.
* g++.dg/ext/fnname3.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71088
138bc75d-0d04-0410-961f-
82ee72b054a4
+2003-09-04 Matt Austern <austern@apple.com>
+
+ * c-common.c (fname_as_string): Use lang_hooks.decl_printable_name
+ with verbosity 0, instead of DECL_NAME, for human-readable string.
+
2003-09-04 Eric Christopher <echristo@redhat.com>
* targhooks.c (default_return_in_memory): Allow
const char *
fname_as_string (int pretty_p)
{
- const char *name = NULL;
-
- if (pretty_p)
- name = (current_function_decl
- ? (*lang_hooks.decl_printable_name) (current_function_decl, 2)
- : "top level");
- else if (current_function_decl && DECL_NAME (current_function_decl))
- name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
- else
- name = "";
+ const char *name = "top level";
+ int vrb = 2;
+
+ if (! pretty_p)
+ {
+ name = "";
+ vrb = 0;
+ }
+
+ if (current_function_decl)
+ name = (*lang_hooks.decl_printable_name) (current_function_decl, vrb);
+
return name;
}
+2003-09-04 Matt Austern <austern@apple.com>
+
+ * g++.dg/ext/fnname1.C: New test. (__func__ for C++.)
+ * g++.dg/ext/fnname2.C: Likewise.
+ * g++.dg/ext/fnname3.C: Likewise.
+
2003-09-04 Mark Mitchell <mark@codesourcery.com>
* g++.dg/expr/lval1.C: New test.
--- /dev/null
+// Test whether __func__ works for namespace-scope C++ functions.
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Matt Austern <austern@apple.com>, 3 Aug 2003
+// { dg-do run }
+
+namespace xyzzy
+{
+ const char* ab6(double, void*)
+ {
+ return __func__;
+ }
+}
+
+int main()
+{
+ const char* s = xyzzy::ab6(2.3, (void*) 0);
+ bool ok = true;
+
+ ok = ok && s[0] == 'a';
+ ok = ok && s[1] == 'b';
+ ok = ok && s[2] == '6';
+ ok = ok && s[3] == '\0';
+
+ return ok ? 0 : 1;
+}
--- /dev/null
+// Test whether __func__ works for ordinary member functions.
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Matt Austern <austern@apple.com>, 3 Aug 2003
+// { dg-do run }
+
+struct y8a
+{
+ const char* zqjx(int, char);
+};
+
+const char* y8a::zqjx(int, char)
+{
+ return __func__;
+}
+
+
+int main()
+{
+ y8a tmp;
+ const char* s = tmp.zqjx(16, 'x');
+ bool ok = true;
+
+ ok = ok && s[0] == 'z';
+ ok = ok && s[1] == 'q';
+ ok = ok && s[2] == 'j';
+ ok = ok && s[3] == 'x';
+ ok = ok && s[4] == '\0';
+
+ return ok ? 0 : 1;
+}
--- /dev/null
+// Test whether __func__ works for constructors and destructors.
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Matt Austern <austern@apple.com>, 3 Aug 2003
+// { dg-do run }
+
+struct uk9i
+{
+ uk9i();
+ ~uk9i();
+
+ static const char* fname;
+ static bool obj_exists;
+};
+
+uk9i::uk9i()
+{
+ obj_exists = true;
+ fname = __func__;
+}
+
+uk9i::~uk9i()
+{
+ obj_exists = false;
+ fname = __func__;
+}
+
+const char* uk9i::fname = 0;
+bool uk9i::obj_exists = false;
+
+int main()
+{
+ bool ok = true;
+
+ ok = ok && uk9i::fname == 0;
+ ok = ok && !uk9i::obj_exists;
+
+ {
+ uk9i tmp;
+ ok = ok && uk9i::obj_exists;
+ ok = ok && uk9i::fname != 0;
+ if (ok)
+ {
+ ok = ok && uk9i::fname[0] == 'u';
+ ok = ok && uk9i::fname[1] == 'k';
+ ok = ok && uk9i::fname[2] == '9';
+ ok = ok && uk9i::fname[3] == 'i';
+ ok = ok && uk9i::fname[4] == '\0';
+ }
+ }
+
+ ok = ok && !uk9i::obj_exists;
+ ok = ok && uk9i::fname != 0;
+ if (ok)
+ {
+ ok = ok && uk9i::fname[0] == '~';
+ ok = ok && uk9i::fname[1] == 'u';
+ ok = ok && uk9i::fname[2] == 'k';
+ ok = ok && uk9i::fname[3] == '9';
+ ok = ok && uk9i::fname[4] == 'i';
+ ok = ok && uk9i::fname[5] == '\0';
+ }
+
+ return ok ? 0 : 1;
+}