From ca7f909fba59f79d85f74ee0846bc9ed121ba7b2 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Fri, 15 Mar 2019 13:56:55 +0000 Subject: [PATCH] [PR88534] accept VAR_DECL in class literal template parms 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. for gcc/ChangeLog PR c++/88534 PR c++/88537 * dwarf2out.c (generic_parameter_die): Follow DECL_INITIAL of VAR_DECL args. for gcc/testsuite/ChangeLog PR c++/88534 PR c++/88537 * g++.dg/cpp2a/pr88534.C: New. * g++.dg/cpp2a/pr88537.C: New. From-SVN: r269709 --- gcc/ChangeLog | 7 +++ gcc/dwarf2out.c | 7 +++ gcc/testsuite/ChangeLog | 7 +++ gcc/testsuite/g++.dg/cpp2a/pr88534.C | 65 ++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/pr88537.C | 16 +++++++ 5 files changed, 102 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/ChangeLog b/gcc/ChangeLog index d7a4f3832d7..dfec5891a93 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-03-15 Alexandre Oliva + + PR c++/88534 + PR c++/88537 + * dwarf2out.c (generic_parameter_die): Follow DECL_INITIAL of + VAR_DECL args. + 2019-03-15 Jakub Jelinek PR c++/89709 diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index d9cefd3e1d3..251fff7b9ae 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -13603,6 +13603,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 (arg && VAR_P (arg)) + arg = DECL_INITIAL (arg); + if (!parm || !DECL_NAME (parm) || !arg) return NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 285dc51b5e7..139e45a6802 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-03-15 Alexandre Oliva + + PR c++/88534 + PR c++/88537 + * g++.dg/cpp2a/pr88534.C: New. + * g++.dg/cpp2a/pr88537.C: New. + 2019-03-15 Robin Dapp * gcc.target/s390/target-attribute/tattr-1.c (htm0): -mhtm -> '-mhtm'. diff --git a/gcc/testsuite/g++.dg/cpp2a/pr88534.C b/gcc/testsuite/g++.dg/cpp2a/pr88534.C new file mode 100644 index 00000000000..54faf385f11 --- /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 +struct integer_sequence +{ + typedef T value_type; + static constexpr size_t size () noexcept { return sizeof...(I); } +}; + +template +using make_integer_sequence = integer_sequence; + +template +using index_sequence = integer_sequence; + +template +using make_index_sequence = make_integer_sequence; +} + +template struct S +{ + T content[N]; + using char_type = T; + template + constexpr S (const T (&input)[N], std::index_sequence) noexcept : content{input[I]...} { } + constexpr S (const T (&input)[N]) noexcept : S (input, std::make_index_sequence ()) { } + 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 S (const T (&)[N]) -> S; + +template +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 00000000000..d558d45f578 --- /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 void fnc() { + +} + +void f() { + fnc(); +} -- 2.30.2