aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Austern <austern@apple.com>2003-09-04 21:32:48 +0000
committerMatt Austern <austern@gcc.gnu.org>2003-09-04 21:32:48 +0000
commit47ab33b2208b4fc4a043f8e337a0cf70fa23e3eb (patch)
treeeca3e9ad4309c329d418909982ba204fe37e9b70
parentbe6acd4b3a2c3a23baa80c11899a3cbb0969662b (diff)
downloadgcc-47ab33b2208b4fc4a043f8e337a0cf70fa23e3eb.zip
gcc-47ab33b2208b4fc4a043f8e337a0cf70fa23e3eb.tar.gz
gcc-47ab33b2208b4fc4a043f8e337a0cf70fa23e3eb.tar.bz2
Correct the behavior of __func__ for C++ special member functions.
* 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. From-SVN: r71088
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-common.c22
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/ext/fnname1.C26
-rw-r--r--gcc/testsuite/g++.dg/ext/fnname2.C31
-rw-r--r--gcc/testsuite/g++.dg/ext/fnname3.C65
6 files changed, 145 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e2c0fc6..a3ebefc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 9dd1826..69dd0811 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -1071,16 +1071,18 @@ finish_fname_decls (void)
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;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 562ed09..c475b9a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+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.
diff --git a/gcc/testsuite/g++.dg/ext/fnname1.C b/gcc/testsuite/g++.dg/ext/fnname1.C
new file mode 100644
index 0000000..521d5a7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/fnname1.C
@@ -0,0 +1,26 @@
+// 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;
+}
diff --git a/gcc/testsuite/g++.dg/ext/fnname2.C b/gcc/testsuite/g++.dg/ext/fnname2.C
new file mode 100644
index 0000000..ea0c182
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/fnname2.C
@@ -0,0 +1,31 @@
+// 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;
+}
diff --git a/gcc/testsuite/g++.dg/ext/fnname3.C b/gcc/testsuite/g++.dg/ext/fnname3.C
new file mode 100644
index 0000000..c29170a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/fnname3.C
@@ -0,0 +1,65 @@
+// 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;
+}