public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: C++ PATCH for c++/88538 - braced-init-list in template-argument-list
Date: Mon, 07 Jan 2019 23:56:00 -0000	[thread overview]
Message-ID: <20190107235642.GI28316@redhat.com> (raw)

At the risk of seeming overly eager, I thought it would be reasonable to
go with the following: enabling braced-init-list as a template-argument.
As the discussion on the reflector clearly indicates, this was the intent
from the get-go.

I know, it's not a regression.  But I restricted the change to C++20, and it
should strictly allow code that wasn't accepted before -- when a template
argument starts with {.  Perhaps we could even drop the C++20 check.

What's your preference?

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-01-07  Marek Polacek  <polacek@redhat.com>

	PR c++/88538 - braced-init-list in template-argument-list.
	* parser.c (cp_parser_template_argument): Handle braced-init-list when
	in C++20.

	* g++.dg/cpp2a/nontype-class11.C: New test.

diff --git gcc/cp/parser.c gcc/cp/parser.c
index bca1739ace3..7de2ee28b20 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -16892,7 +16892,18 @@ cp_parser_template_argument (cp_parser* parser)
       return argument;
     }
   /* It must be a non-type argument.  In C++17 any constant-expression is
-     allowed.  */
+     allowed.  In C++20, we can encounter a braced-init-list.  */
+  if (cxx_dialect >= cxx2a
+      && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+    {
+      cp_parser_parse_tentatively (parser);
+      bool expr_non_constant_p;
+      argument = cp_parser_braced_list (parser, &expr_non_constant_p);
+      if (cp_parser_parse_definitely (parser))
+	/* Yup, it was a braced-init-list.  */
+	return argument;
+    }
+
   if (cxx_dialect > cxx14)
     goto general_expr;
 
diff --git gcc/testsuite/g++.dg/cpp2a/nontype-class11.C gcc/testsuite/g++.dg/cpp2a/nontype-class11.C
new file mode 100644
index 00000000000..8a06d23904b
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp2a/nontype-class11.C
@@ -0,0 +1,21 @@
+// PR c++/88538
+// { dg-do compile { target c++2a } }
+
+struct S {
+  unsigned a;
+  unsigned b;
+  constexpr S(unsigned _a, unsigned _b) noexcept: a{_a}, b{_b} { }
+};
+
+template <S p>
+void fnc()
+{
+}
+
+template<S s> struct X { };
+
+void f()
+{
+  fnc<{10,20}>();
+  X<{1, 2}> x;
+}

             reply	other threads:[~2019-01-07 23:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07 23:56 Marek Polacek [this message]
2019-01-08  2:53 ` Jason Merrill
2019-01-08 15:42   ` Marek Polacek
2019-01-08 20:46     ` Jason Merrill
2019-01-08 22:35       ` Marek Polacek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190107235642.GI28316@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).