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++/88373, wrong parse error with ~
Date: Thu, 06 Dec 2018 16:33:00 -0000	[thread overview]
Message-ID: <20181206163316.GM21364@redhat.com> (raw)

This patch fixes a bogus parse error with ~ in a template-argument-list.  We have

  S<int, ~value <int>>

and cp_parser_template_argument just tries to parse each argument as a type,
id-expression, etc to see what sticks.  When it sees ~value, it tries to parse
it using cp_parser_class_name (because of the ~), which ends up calling
cp_parser_lookup_name, looking for "value", but finds nothing.  Since it's an
unqualified-id followed by <, we treat "~value<int>" as a template name
function.  It isn't followed by "(args)", so we simulate parse error.  As a
consequence of this error, the parsing of the outermost template-id S fails.

The problem is that when we're looking up the name in cp_parser_class_name,
tag_type is typename_type, which means bindings that do not refer to types
are ignored, so the variable template "value" isn't found and we're toast.

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

2018-12-06  Marek Polacek  <polacek@redhat.com>

	PR c++/88373 - wrong parse error with ~.
	* parser.c (cp_parser_template_name): Check tag_type for
	none_type.

	* g++.dg/cpp2a/fn-template19.C: New test.

diff --git gcc/cp/parser.c gcc/cp/parser.c
index ac19cb4b9bb..2f55855ce9f 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -16579,7 +16579,8 @@ cp_parser_template_name (cp_parser* parser,
       if (!found
 	  && (cxx_dialect > cxx17)
 	  && !scoped_p
-	  && cp_lexer_next_token_is (parser->lexer, CPP_LESS))
+	  && cp_lexer_next_token_is (parser->lexer, CPP_LESS)
+	  && tag_type == none_type)
 	{
 	  /* [temp.names] says "A name is also considered to refer to a template
 	     if it is an unqualified-id followed by a < and name lookup finds
diff --git gcc/testsuite/g++.dg/cpp2a/fn-template19.C gcc/testsuite/g++.dg/cpp2a/fn-template19.C
new file mode 100644
index 00000000000..1d6b43bb7ce
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp2a/fn-template19.C
@@ -0,0 +1,11 @@
+// PR c++/88373
+// { dg-do compile }
+// { dg-options "-std=c++2a" }
+
+template <class T>
+constexpr T value = T {};
+
+template <class T, T t>
+struct S {};
+
+using U = S <int, ~value <int>>;

             reply	other threads:[~2018-12-06 16:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 16:33 Marek Polacek [this message]
2018-12-06 19:39 ` Jason Merrill

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=20181206163316.GM21364@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).