Thread overview
[Issue 19002] __FUNCTION__ and __PRETTY_FUNCTION__ cannot be used as C string literals
[Issue 19002] __FUNCTION__ and __PRETTY_FUNCTION__ are not C string literals
Jun 27, 2018
Seb
May 30, 2019
Basile-z
May 30, 2019
Dlang Bot
May 30, 2019
Dlang Bot
Mar 21, 2020
Basile-z
Jul 26, 2021
Dlang Bot
June 27, 2018
https://issues.dlang.org/show_bug.cgi?id=19002

Seb <greensunny12@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com

--- Comment #1 from Seb <greensunny12@gmail.com> ---
This is expected as all string literals should be zero-terminated D strings. So the following works as expected:

```
void main()
{
   import core.stdc.stdio;
   printf(__FUNCTION__.ptr);
}
```

The interesting bit is why __FILE__ and __MODULE__ can be passed directly to printf.

--
June 27, 2018
https://issues.dlang.org/show_bug.cgi?id=19002

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
No, this is not expected. I can use printf with a string literal, and it works, even if it's via an enum, or some const folding. The compiler implicitly can cast a string literal to a const(char*), otherwise using C functions with string literals would be painful.

For example:

printf("hello" ~ "\n"); // ok
enum x = "hello";
printf(x); // ok
enum y = __FUNCTION__;
printf(y); // nope
enum z = ctfeFunction();
printf(z); // nope

I think all of these should work, they are all string literals, and should be 0 terminated.

--
June 27, 2018
https://issues.dlang.org/show_bug.cgi?id=19002

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|__FUNCTION__ and            |__FUNCTION__ and
                   |__PRETTY_FUNCTION__ are not |__PRETTY_FUNCTION__ cannot
                   |C string literals           |be used as C string
                   |                            |literals

--
May 30, 2019
https://issues.dlang.org/show_bug.cgi?id=19002

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |pull
                 CC|                            |b2.temp@gmx.com

--- Comment #3 from Basile-z <b2.temp@gmx.com> ---
pull : https://github.com/dlang/dmd/pull/9920

--
May 30, 2019
https://issues.dlang.org/show_bug.cgi?id=19002

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@Basile-z updated dlang/dmd pull request #9920 "fix issue 19002 - __FUNCTION__ and __PRETTY_FUNCTION__ cannot be used  as C string literals" fixing this issue:

- fix issue 19002 - __FUNCTION__ and __PRETTY_FUNCTION__ cannot be used as C string literals

https://github.com/dlang/dmd/pull/9920

--
May 30, 2019
https://issues.dlang.org/show_bug.cgi?id=19002

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #9920 "fix issue 19002 - __FUNCTION__ and __PRETTY_FUNCTION__ cannot be used  as C string literals" was merged into stable:

- 748fee406f8be6279d687be4acafa119fcdecaa4 by Basile Burg:
  fix issue 19002 - __FUNCTION__ and __PRETTY_FUNCTION__ cannot be used as C
string literals

https://github.com/dlang/dmd/pull/9920

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=19002

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--
July 26, 2021
https://issues.dlang.org/show_bug.cgi?id=19002

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #12923 "[dmd-cxx] fix issue 19002 - __FUNCTION__ and __PRETTY_FUNCTION__ cannot be used as C string literals" was merged into dmd-cxx:

- c42fda99f18c0258bebdbb9958cf86a8c602a1bf by Basile Burg:
  [dmd-cxx] fix issue 19002 - __FUNCTION__ and __PRETTY_FUNCTION__ cannot be
used as C string literals

https://github.com/dlang/dmd/pull/12923

--