[C++ Patch] PR 55425

2014-11-19 Thread Paolo Carlini

Hi,

today I wanted to simply close this Bug as fixed, but then I noticed 
that Richard Smith in the audit trail argued, correctly in my opinion, 
that we should accept things like:


constexpr const char* x() { return __func__; }

in C++11 mode too, because the as if local variable specification of 
__func__ in the Standard doesn't matter for the purpose of constexpr, 
because otherwise in C++11 no constexpr function would be valid: the 
Standard does *not* say that __func__ is only predefined if it is used.


That said, I think a quick way to accept __func__, __FUNCTION__, and 
__PRETTY_FUNCTION__ is checking whether DECL_ARTIFICIAL (decl) is true 
on the decl. Tested x86_64-linux.


Thanks,
Paolo.

///
/cp
2014-11-19  Paolo Carlini  paolo.carl...@oracle.com

PR c++/55425
* constexpr.c (constexpr_fn_retval): Accept __func__, __FUNCTION__,
and __PRETTY_FUNCTION__.

/testsuite
2014-11-19  Paolo Carlini  paolo.carl...@oracle.com

PR c++/55425
* g++.dg/cpp0x/constexpr-__func__.C
Index: cp/constexpr.c
===
--- cp/constexpr.c  (revision 217755)
+++ cp/constexpr.c  (working copy)
@@ -616,9 +616,14 @@ constexpr_fn_retval (tree body)
   return break_out_target_exprs (TREE_OPERAND (body, 0));
 
 case DECL_EXPR:
-  if (TREE_CODE (DECL_EXPR_DECL (body)) == USING_DECL)
-   return NULL_TREE;
-  return error_mark_node;
+  {
+   tree decl = DECL_EXPR_DECL (body);
+   if (TREE_CODE (decl) == USING_DECL
+   /* Accept __func__, __FUNCTION__, and __PRETTY_FUNCTION__.  */
+   || DECL_ARTIFICIAL (decl))
+ return NULL_TREE;
+   return error_mark_node;
+  }
 
 case CLEANUP_POINT_EXPR:
   return constexpr_fn_retval (TREE_OPERAND (body, 0));
Index: testsuite/g++.dg/cpp0x/constexpr-__func__.C
===
--- testsuite/g++.dg/cpp0x/constexpr-__func__.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-__func__.C (working copy)
@@ -0,0 +1,6 @@
+// PR c++/55425
+// { dg-do compile { target c++11 } }
+
+constexpr const char* x() { return __func__; }
+constexpr const char* y() { return __FUNCTION__; }
+constexpr const char* z() { return __PRETTY_FUNCTION__; }


Re: [C++ Patch] PR 55425

2014-11-19 Thread Jason Merrill

OK.

Jason