public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ debug PATCH] [PR88534] accept VAR_DECL in class literal template parms
@ 2019-03-14 20:20 Alexandre Oliva
  2019-03-14 20:22 ` Marek Polacek
  0 siblings, 1 reply; 18+ messages in thread
From: Alexandre Oliva @ 2019-03-14 20:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan, ccoutant

P0732R2 / C++ 2a introduce class literals as template parameters.  The
front-end uses VAR_DECLs constructed from such literals to bind the
template PARM_DECLs, but dwarf2out.c used to reject such VAR_DECLs.

Taking DECL_INITIAL from such VAR_DECLs enables the generation of
DW_AT_const_value for them, at least when the class literal can
actually be represented as such.

Regstrapped on x86_64- and i686-linux-gnu.  Ok to install?


for  gcc/ChangeLog

	PR c++/88534
	PR c++/88537
	* dwarf2out.c (generic_parameter_die): Follow DECL_INITIAL of
	VAR_DECL args.

for  gcc/ChangeLog

	PR c++/88534
	PR c++/88537
	* g++.dg/cpp2a/pr88534.C: New.
	* g++.dg/cpp2a/pr88537.C: New.
---
 gcc/dwarf2out.c                      |    7 ++++
 gcc/testsuite/g++.dg/cpp2a/pr88534.C |   65 ++++++++++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/pr88537.C |   16 ++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/pr88534.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/pr88537.C

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 8305555681447..478d9b9b289b1 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -13601,6 +13601,13 @@ generic_parameter_die (tree parm, tree arg,
   dw_die_ref tmpl_die = NULL;
   const char *name = NULL;
 
+  /* C++2a accepts class literals as template parameters, and var
+     decls with initializers represent them.  The VAR_DECLs would be
+     rejected, but we can take the DECL_INITIAL constructor and
+     attempt to expand it.  */
+  if (TREE_CODE (arg) == VAR_DECL)
+    arg = DECL_INITIAL (arg);
+
   if (!parm || !DECL_NAME (parm) || !arg)
     return NULL;
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/pr88534.C b/gcc/testsuite/g++.dg/cpp2a/pr88534.C
new file mode 100644
index 0000000000000..54faf385f11aa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/pr88534.C
@@ -0,0 +1,65 @@
+// { dg-do compile { target c++2a } }
+// { dg-options "-g" }
+
+typedef __SIZE_TYPE__ size_t;
+
+namespace std
+{
+
+template <typename T, T... I>
+struct integer_sequence
+{
+  typedef T value_type;
+  static constexpr size_t size () noexcept { return sizeof...(I); }
+};
+
+template <typename T, T N>
+using make_integer_sequence = integer_sequence<T, __integer_pack (N)...>;
+
+template <size_t... I>
+using index_sequence = integer_sequence<size_t, I...>;
+
+template <size_t N>
+using make_index_sequence = make_integer_sequence<size_t, N>;
+}
+
+template <typename T, size_t N> struct S
+{
+  T content[N];
+  using char_type = T;
+  template <size_t... I>
+  constexpr S (const T (&input)[N], std::index_sequence<I...>) noexcept : content{input[I]...} { }
+  constexpr S (const T (&input)[N]) noexcept : S (input, std::make_index_sequence<N> ()) { }
+  constexpr size_t size () const noexcept
+  {
+    if (content[N - 1] == '\0')
+      return N - 1;
+    else
+      return N;
+  }
+  constexpr T operator[] (size_t i) const noexcept
+  {
+    return content[i];
+  }
+  constexpr const T *begin () const noexcept
+  {
+    return content;
+  }
+  constexpr const T *end () const noexcept
+  {
+    return content + size ();
+  }
+};
+
+template <typename T, size_t N> S (const T (&)[N]) -> S<T, N>;
+
+template <S S>
+struct F
+{
+};
+
+auto
+foo ()
+{
+  F<"test"> f;
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/pr88537.C b/gcc/testsuite/g++.dg/cpp2a/pr88537.C
new file mode 100644
index 0000000000000..d558d45f57830
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/pr88537.C
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++2a } }
+// { dg-options "-g" }
+
+struct pair {
+	unsigned a;
+	unsigned b;
+	constexpr pair(unsigned _a, unsigned _b) noexcept: a{_a}, b{_b} { }
+};
+
+template <pair p> void fnc() {
+	
+}
+
+void f() {
+    fnc<pair(10,20)>();
+}

-- 
Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
Be the change, be Free!         FSF Latin America board member
GNU Toolchain Engineer                Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe

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

end of thread, other threads:[~2019-03-29 15:02 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14 20:20 [C++ debug PATCH] [PR88534] accept VAR_DECL in class literal template parms Alexandre Oliva
2019-03-14 20:22 ` Marek Polacek
2019-03-14 20:33   ` Jason Merrill
2019-03-15 13:57     ` Alexandre Oliva
2019-03-20 17:13       ` Marek Polacek
2019-03-20 20:05         ` Alexandre Oliva
2019-03-20 21:58           ` Marek Polacek
2019-03-20 22:06             ` Jakub Jelinek
2019-03-20 22:20               ` Marek Polacek
2019-03-21 19:12                 ` Jason Merrill
2019-03-27 11:06                   ` Jonathan Wakely
2019-03-27 21:36                     ` Martin Sebor
2019-03-28  6:47                       ` Martin Sebor
2019-03-28 17:49                         ` Jason Merrill
2019-03-29  0:07                           ` Martin Sebor
2019-03-29 15:08                             ` Jason Merrill
2019-03-27 17:02                   ` Martin Sebor
2019-03-27 21:01                     ` Jason Merrill

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