On 04/26/2016 05:59 PM, Martin Sebor wrote:
PR c++/66639 asked to declare __func__ , __FUNCTION__ and
__PRETTY_FUNCTION__ as constexpr​.  With the request fulfilled
sometime in the 6.0 time frame (possibly as a result of fixing
c++/70353), the attached patch implements the corresponding
change suggested in c++/66561 - __builtin_LINE at al. should
yield constant expression, and updates the manual to reflect
both.  It has been tested on x86_64 Linux.

Martin

gcc-66561.patch


PR c++/66561 - __builtin_LINE at al. should yield constant expressions
PR c++/66639 - declare __func__ , __FUNCTION__ & __PRETTY_FUNCTION__ constexpr

gcc/testsuite/ChangeLog:
2016-04-26  Martin Sebor  <mse...@redhat.com>

        PR c++/66561
        * c-c++-common/builtin_location.c: New test.
        * g++.dg/cpp1y/builtin_location.C: New test.

gcc/cp/ChangeLog:
2016-04-26  Martin Sebor  <mse...@redhat.com>

        PR c++/66561
        * tree.c (builtin_valid_in_constant_expr_p): Treat BUILT_IN_FILE,
        BUILT_IN_FUNCTION, and BUILT_IN_LINE as constant expressions.

gcc/ChangeLog:
2016-04-26  Martin Sebor  <mse...@redhat.com>

        PR c++/66561
        * builtins.c (fold_builtin_FILE): New function.
        (fold_builtin_FUNCTION, fold_builtin_LINE): New functions.
        (fold_builtin_0): Call them.

        PR c++/66561
        * doc/extend.texi (Other Builtins): Update __builtin_FILE,
        __builtin_FUNCTION, and __builtin_LINE to reflect they yield
        constants.

        PR c++/66639
        * doc/extend.texi (Function Names as Strings): Update __func__,
        __FUNCTION__, __PRETTY_FUNCTION__ to reflect they evaluate to
        constants.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3d89baf..44c4f63 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7927,6 +7927,39 @@ fold_builtin_arith_overflow (location_t loc, enum 
built_in_function fcode,
   return build2_loc (loc, COMPOUND_EXPR, boolean_type_node, store, ovfres);
 }

+/* Fold __builtin_FILE() to a constant string.  */
NIT: When we refer to functions, we don't have the trailing(). So drop it from the comment.

+
+/* Fold __builtin_FUNCTION() to a constant string.  */
Similarly.

+
+/* Fold __builtin_LINE() to an integer constant.  */
Similarly.

So the big question I have is why we have to treat these differently than __func__ __FUNCTION__ and __PRETTY_FUNCTION__.

Which leads me to:

constexpr_fn_retval which has:

   case DECL_EXPR:
      {
        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;
      }

Is the distinction here that the _builtin_XXX are essentially functions, yet the others are _DECLs? Thus we have to fold the builtin function so that it is considered a constant?


jeff

Reply via email to