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
This commit is contained in:
parent
be6acd4b3a
commit
47ab33b220
6 changed files with 144 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -1071,16 +1071,18 @@ finish_fname_decls (void)
|
|||
const char *
|
||||
fname_as_string (int pretty_p)
|
||||
{
|
||||
const char *name = NULL;
|
||||
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);
|
||||
|
||||
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 = "";
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
26
gcc/testsuite/g++.dg/ext/fnname1.C
Normal file
26
gcc/testsuite/g++.dg/ext/fnname1.C
Normal file
|
@ -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;
|
||||
}
|
31
gcc/testsuite/g++.dg/ext/fnname2.C
Normal file
31
gcc/testsuite/g++.dg/ext/fnname2.C
Normal file
|
@ -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;
|
||||
}
|
65
gcc/testsuite/g++.dg/ext/fnname3.C
Normal file
65
gcc/testsuite/g++.dg/ext/fnname3.C
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Reference in a new issue