public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.
@ 2017-06-28 12:53 Snaipe
  2017-06-28 12:57 ` Franklin Mathieu
  0 siblings, 1 reply; 6+ messages in thread
From: Snaipe @ 2017-06-28 12:53 UTC (permalink / raw)
  To: snaipe, gcc-patches; +Cc: Snaipe

From: Snaipe <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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.
  2017-06-28 12:53 [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr Snaipe
@ 2017-06-28 12:57 ` Franklin Mathieu
  0 siblings, 0 replies; 6+ messages in thread
From: Franklin Mathieu @ 2017-06-28 12:57 UTC (permalink / raw)
  To: gcc-patches

Sorry about that (--dry-run fail), please ignore.

On Wed, Jun 28, 2017 at 1:53 PM, Snaipe <snaipe@arista.com> wrote:
> From: Snaipe <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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.
  2017-06-28 12:49 Franklin “Snaipe” Mathieu
@ 2017-06-28 13:06 ` Franklin Mathieu
  0 siblings, 0 replies; 6+ messages in thread
From: Franklin Mathieu @ 2017-06-28 13:06 UTC (permalink / raw)
  To: Franklin Mathieu, gcc-patches

Sorry about the two other failed attempts. I got confused about the
output of send-email and ended up sending two follow-up bogus emails.

This is the right email chain.

On Wed, Jun 28, 2017 at 1:49 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.
  2017-06-28 12:52 Franklin Snaipe Mathieu
@ 2017-06-28 12:56 ` Franklin Mathieu
  0 siblings, 0 replies; 6+ messages in thread
From: Franklin Mathieu @ 2017-06-28 12:56 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.
@ 2017-06-28 12:52 Franklin Snaipe Mathieu
  2017-06-28 12:56 ` Franklin Mathieu
  0 siblings, 1 reply; 6+ messages in thread
From: Franklin Snaipe Mathieu @ 2017-06-28 12:52 UTC (permalink / raw)
  To: snaipe, gcc-patches; +Cc: Franklin "Snaipe" Mathieu

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr.
@ 2017-06-28 12:49 Franklin “Snaipe” Mathieu
  2017-06-28 13:06 ` Franklin Mathieu
  0 siblings, 1 reply; 6+ messages in thread
From: Franklin “Snaipe” Mathieu @ 2017-06-28 12:49 UTC (permalink / raw)
  To: snaipe, gcc-patches; +Cc: Franklin “Snaipe” Mathieu

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-06-28 13:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-28 12:53 [PATCH v1] cxx: Make __func__, __FUNCTION__, and __PRETTY_FUNCTION__ constexpr Snaipe
2017-06-28 12:57 ` Franklin Mathieu
  -- strict thread matches above, loose matches on Subject: below --
2017-06-28 12:52 Franklin Snaipe Mathieu
2017-06-28 12:56 ` Franklin Mathieu
2017-06-28 12:49 Franklin “Snaipe” Mathieu
2017-06-28 13:06 ` Franklin Mathieu

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).