builtins.c (fold_builtin_FUNCTION): Use lang_hooks.decl_printable_name.
authorNathan Sidwell <nathan@acm.org>
Thu, 29 Jun 2017 14:00:44 +0000 (14:00 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 29 Jun 2017 14:00:44 +0000 (14:00 +0000)
gcc/
* builtins.c (fold_builtin_FUNCTION): Use
lang_hooks.decl_printable_name.

gcc/cp/
* g++.dg/cpp1y/builtin_FUNCTION.C: New.

From-SVN: r249784

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/builtin_FUNCTION.C [new file with mode: 0644]

index c11b478777afc8fea903aa2ae92037c77ce645a8..f230dad271a7e7ccf4e233b08756c6814a7a75b6 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-29  Nathan Sidwell  <nathan@acm.org>
+
+       * builtins.c (fold_builtin_FUNCTION): Use
+       lang_hooks.decl_printable_name.
+
 2017-06-29  Peter Bergner  <bergner@vnet.ibm.com>
 
        PR middle-end/81194
index 7e829ef1408c9b6feb5cc939c98dd77f9ca41995..034ec2e4cb03742ded872ac55bbdf44f0b6ed389 100644 (file)
@@ -8739,13 +8739,12 @@ fold_builtin_FILE (location_t loc)
 static inline tree
 fold_builtin_FUNCTION ()
 {
+  const char *name = "";
+
   if (current_function_decl)
-    {
-      const char *name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
-      return build_string_literal (strlen (name) + 1, name);
-    }
+    name = lang_hooks.decl_printable_name (current_function_decl, 0);
 
-  return build_string_literal (1, "");
+  return build_string_literal (strlen (name) + 1, name);
 }
 
 /* Fold a call to __builtin_LINE to an integer constant.  */
index 2f0b29ba7004655b4a13251e49d44db87f4173ac..70651d5f3ab0ee4d93551a7ed73773779553f237 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-29  Nathan Sidwell  <nathan@acm.org>
+
+       * g++.dg/cpp1y/builtin_FUNCTION.C: New.
+
 2017-06-29  Peter Bergner  <bergner@vnet.ibm.com>
 
        PR middle-end/81194
diff --git a/gcc/testsuite/g++.dg/cpp1y/builtin_FUNCTION.C b/gcc/testsuite/g++.dg/cpp1y/builtin_FUNCTION.C
new file mode 100644 (file)
index 0000000..680ba63
--- /dev/null
@@ -0,0 +1,42 @@
+// { dg-do run }
+
+#include <string.h>
+
+const char *ct, *dt, *cv;
+
+struct KLASS
+{
+  KLASS () ;
+  ~KLASS ();
+  operator int ();
+};
+
+KLASS::KLASS()
+{
+  ct = __builtin_FUNCTION ();
+}
+
+KLASS::~KLASS ()
+{
+  dt = __builtin_FUNCTION ();
+}
+
+KLASS::operator int ()
+{
+  cv = __builtin_FUNCTION ();
+  return 0;
+}
+
+int main ()
+{
+  int q = int (KLASS ());
+
+  if (strcmp (ct, "KLASS"))
+    return 1;
+  if (strcmp (dt, "~KLASS"))
+    return 2;
+  if (strcmp (cv, "operator int"))
+    return 3;
+
+  return 0;
+}