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++/88184, ICE when treating name as template-name
Date: Wed, 28 Nov 2018 15:48:00 -0000	[thread overview]
Message-ID: <20181128154849.GD3269@redhat.com> (raw)

Since P0846R0 was implemented, a name will be treated as a template-name when
it is an unqualified-id followed by a < and name lookup finds either one or
more functions or finds nothing, in order to potentially cause ADL to be performed.

In this case, we had

  f<T> ();

where we'd found a decl for f (not a TEMPLATE_DECL) and < follows.  But there
are no arguments, so ADL can't be performed, so I think let's diagnose this
problem sooner lest things break later in finish_call_expr.

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

2018-11-28  Marek Polacek  <polacek@redhat.com>

	PR c++/88184, ICE when treating name as template-name.
	* parser.c (cp_parser_postfix_expression): Give error when the
	name-as-template-name doesn't have any arguments.

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

diff --git gcc/cp/parser.c gcc/cp/parser.c
index 3a98ed900cd..01097b57eb9 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -7241,6 +7241,20 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 						     complain);
 		      }
 		  }
+		else if (TREE_CODE (postfix_expression) == TEMPLATE_ID_EXPR
+			 && (TREE_CODE (TREE_OPERAND (postfix_expression, 0))
+			     == FUNCTION_DECL)
+			 && args->is_empty ())
+		  {
+		    /* We can get here when treating a name as a template name
+		       (because it was an unqualified-id followed by a < and
+		       name lookup found a decl), but now we see that there
+		       are no arguments, so ADL isn't possible.  */
+		    auto_diagnostic_group d;
+		    error_at (loc, "no matching function for call to %<%D()%>",
+			      postfix_expression.get_value ());
+		    postfix_expression = error_mark_node;
+		  }
 	      }
 
 	    if (TREE_CODE (postfix_expression) == COMPONENT_REF)
diff --git gcc/testsuite/g++.dg/cpp2a/fn-template17.C gcc/testsuite/g++.dg/cpp2a/fn-template17.C
new file mode 100644
index 00000000000..f0d24107682
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp2a/fn-template17.C
@@ -0,0 +1,21 @@
+// PR c++/88184
+// { dg-do compile }
+// { dg-options "-std=c++2a -fchecking=2" }
+
+namespace A
+{
+  void f ();
+}
+
+using A::f;
+
+template <typename T> void g ()
+{
+  f<T> (); // { dg-error "no matching function for call" }
+}
+
+void
+fn ()
+{
+  g<int>();
+}
diff --git gcc/testsuite/g++.dg/cpp2a/fn-template18.C gcc/testsuite/g++.dg/cpp2a/fn-template18.C
new file mode 100644
index 00000000000..7fe5e89ace3
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp2a/fn-template18.C
@@ -0,0 +1,23 @@
+// PR c++/88184
+// { dg-do compile }
+// { dg-options "-std=c++2a -fchecking=2" }
+
+namespace A
+{
+  void f ();
+  void f (int);
+  void f (int, int);
+}
+
+using A::f;
+
+template <typename T> void g ()
+{
+  f<T> (); // { dg-error "no matching function for call" }
+}
+
+void
+fn ()
+{
+  g<int>();
+}

             reply	other threads:[~2018-11-28 15:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 15:48 Marek Polacek [this message]
2018-11-29  3:34 ` Jason Merrill
2018-11-29 18:28   ` Marek Polacek
2018-11-29 21:04     ` Jason Merrill
2018-12-04 17:27       ` Marek Polacek
2018-12-04 19:09         ` 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=20181128154849.GD3269@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).