This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.


Sorry about that, please ignore.

On Wed, Jun 28, 2017 at 1:52 PM, Franklin Snaipe Mathieu
<snaipe@arista.com> wrote:
> From: "Franklin \"Snaipe\" Mathieu" <snaipe@diacritic.io>
>
> This patch makes the forementioned definitions `contexpr` when
> compiling C++11 and above with GNU extensions.
>
> gcc/cp/ChangeLog:
> 2017-06-27  Franklin “Snaipe” Mathieu  <snaipe@diacritic.io>
>
>         PR c++/66639
>         * decl.c (cp_make_fname_decl): Make declaration constexpr.
>
> gcc/testsuite/ChangeLog:
> 2017-06-27  Franklin “Snaipe” Mathieu  <snaipe@diacritic.io>
>
>         PR c++/66639
>         * g++.dg/pr66639.c: New test.
> ---
>  gcc/cp/decl.c                  |  5 +++++
>  gcc/testsuite/g++.dg/pr66639.C | 19 +++++++++++++++++++
>  2 files changed, 24 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pr66639.C
>
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index 8e9a466..740ab71 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -4384,6 +4384,11 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
>    TREE_READONLY (decl) = 1;
>    DECL_ARTIFICIAL (decl) = 1;
>
> +  /* extension: declare __func__, __FUNCTION__, and __PRETTY_FUNCTION__ as
> +     constexpr.  */
> +  if (!flag_iso && cxx_dialect >= cxx11)
> +    DECL_DECLARED_CONSTEXPR_P (decl) = 1;
> +
>    TREE_USED (decl) = 1;
>
>    if (current_function_decl)
> diff --git a/gcc/testsuite/g++.dg/pr66639.C b/gcc/testsuite/g++.dg/pr66639.C
> new file mode 100644
> index 0000000..51a92f9
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr66639.C
> @@ -0,0 +1,19 @@
> +// PR c++/66639
> +// { dg-do compile { target c++11 } }
> +// { dg-options "" }
> +
> +constexpr bool
> +streq(char const *lhs, char const *rhs)
> +{
> +  return *lhs && *rhs
> +     ? *lhs == *rhs && streq(lhs + 1, rhs + 1)
> +     : !*lhs && !*rhs;
> +}
> +
> +int
> +main()
> +{
> +   static_assert (streq(__func__, "main"), "");
> +   static_assert (streq(__FUNCTION__, "main"), "");
> +   static_assert (streq(__PRETTY_FUNCTION__, "int main()"), "");
> +}
> --
> Franklin "Snaipe" Mathieu
> Arista Networks, Ltd
>



-- 
Franklin "Snaipe" Mathieu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]