* [C++ Patch] PR 55425
@ 2014-11-19 13:05 Paolo Carlini
2014-11-19 17:52 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2014-11-19 13:05 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 730 bytes --]
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.
///////////////////
[-- Attachment #2: CL_55425 --]
[-- Type: text/plain, Size: 286 bytes --]
/cp
2014-11-19 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55425
* constexpr.c (constexpr_fn_retval): Accept __func__, __FUNCTION__,
and __PRETTY_FUNCTION__.
/testsuite
2014-11-19 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55425
* g++.dg/cpp0x/constexpr-__func__.C
[-- Attachment #3: patch_55425 --]
[-- Type: text/plain, Size: 1221 bytes --]
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__; }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ Patch] PR 55425
2014-11-19 13:05 [C++ Patch] PR 55425 Paolo Carlini
@ 2014-11-19 17:52 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2014-11-19 17:52 UTC (permalink / raw)
To: Paolo Carlini, gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-19 17:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-19 13:05 [C++ Patch] PR 55425 Paolo Carlini
2014-11-19 17:52 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).