https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66639

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2017-03-24
         Resolution|FIXED                       |---
     Ever confirmed|0                           |1

--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
In my mind this request morphed into one for some way to get the value of the
three symbols in constexpr contexts, which is what the patch committed in
r235845 does (actually it makes it possible for just the first two symbols).

But you're right, in hindsight, as the more comprehensive test case below
shows, the implemented solution doesn't really resolve the request for __func__
et al. being declared constexpr regardless of the context.  Let me reopen it.

$ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C
constexpr int foo ()
{
  static_assert (0 == __builtin_strcmp (__func__, "foo"), "#1");
  static_assert (0 == __builtin_strcmp (__FUNCTION__, "foo"), "#2");
  static_assert (0 == __builtin_strcmp (__PRETTY_FUNCTION__, "constexpr int
foo()"), "#3");

  return 1;
}

static_assert (foo (), "#4");

void bar ()
{
  static_assert (0 == __builtin_strcmp (__func__, "bar"), "#5");
  static_assert (0 == __builtin_strcmp (__FUNCTION__, "bar"), "#6");
  static_assert (0 == __builtin_strcmp (__PRETTY_FUNCTION__, "void bar()"),
"#7");
}

t.C: In function ‘void bar()’:
t.C:14:3: error: non-constant condition for static assertion
   static_assert (0 == __builtin_strcmp (__func__, "bar"), "#5");
   ^~~~~~~~~~~~~
t.C:14:40: error: ‘__builtin_strcmp(((const char*)(& __func__)), ((const
char*)"bar"))’ is not a constant expression
   static_assert (0 == __builtin_strcmp (__func__, "bar"), "#5");
                       ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
t.C:15:3: error: non-constant condition for static assertion
   static_assert (0 == __builtin_strcmp (__FUNCTION__, "bar"), "#6");
   ^~~~~~~~~~~~~
t.C:15:40: error: ‘__builtin_strcmp(((const char*)(& __FUNCTION__)), ((const
char*)"bar"))’ is not a constant expression
   static_assert (0 == __builtin_strcmp (__FUNCTION__, "bar"), "#6");
                       ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
t.C:16:3: error: non-constant condition for static assertion
   static_assert (0 == __builtin_strcmp (__PRETTY_FUNCTION__, "void bar()"),
"#7");
   ^~~~~~~~~~~~~
t.C:16:40: error: ‘__builtin_strcmp(((const char*)(& __PRETTY_FUNCTION__)),
((const char*)"void bar()"))’ is not a constant expression
   static_assert (0 == __builtin_strcmp (__PRETTY_FUNCTION__, "void bar()"),
"#7");
                       ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to