From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/79056, C++17 ICE with invalid template-id
Date: Fri, 23 Jun 2017 23:31:00 -0000 [thread overview]
Message-ID: <CADzB+2mp0t4NxNSQmWeZnW19u_cL6an7evXSonc0Kmt-UT+Xog@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 884 bytes --]
In this testcase, in C++17 mode after parsing the template-id fails,
we try to treat the template-name as a class template deduction
placeholder, producing an auto type, and then we try to take its
TREE_TYPE when calling cp_parser_check_for_invalid_type_id, which
doesn't work because it's a type, not a TYPE_DECL. Fixed by removing
the TREE_TYPE and adjusting cp_parser_check_for_invalid_type_id to
handle TYPE_DECL.
Really we shouldn't be creating a deduction placeholder in the first
place when the template name is followed by <, but that distinction
shouldn't affect well-formed code since we try to parse a template-id
first.
I still want to improve our handling of parse errors in template-ids;
we never actually diagnose the syntax error here because it's
swallowed by tentative parsing, we just say "argument 1 is invalid".
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 79056.diff --]
[-- Type: text/plain, Size: 2924 bytes --]
commit bbea244e8042460d49970b7fffce13f79e58d8e9
Author: Jason Merrill <jason@redhat.com>
Date: Tue Jun 20 15:32:06 2017 -0400
PR c++/79056 - C++17 ICE with invalid template syntax.
* parser.c (cp_parser_simple_type_specifier): Don't assume that type
is a TYPE_DECL.
(cp_parser_check_for_invalid_template_id): Handle TYPE_DECL.
* pt.c (template_placeholder_p): New.
* cp-tree.h: Declare it.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 40c113b..33dde15 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6413,6 +6413,7 @@ extern void check_template_variable (tree);
extern tree make_auto (void);
extern tree make_decltype_auto (void);
extern tree make_template_placeholder (tree);
+extern bool template_placeholder_p (tree);
extern tree do_auto_deduction (tree, tree, tree);
extern tree do_auto_deduction (tree, tree, tree,
tsubst_flags_t,
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ddb1cf3..97cd923 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2983,7 +2983,9 @@ cp_parser_check_for_invalid_template_id (cp_parser* parser,
if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
{
- if (TYPE_P (type))
+ if (TREE_CODE (type) == TYPE_DECL)
+ type = TREE_TYPE (type);
+ if (TYPE_P (type) && !template_placeholder_p (type))
error_at (location, "%qT is not a template", type);
else if (identifier_p (type))
{
@@ -17060,7 +17062,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
/* There is no valid C++ program where a non-template type is
followed by a "<". That usually indicates that the user
thought that the type was a template. */
- cp_parser_check_for_invalid_template_id (parser, TREE_TYPE (type),
+ cp_parser_check_for_invalid_template_id (parser, type,
none_type,
token->location);
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index fba7fb1..392fba0 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -24799,6 +24799,14 @@ make_template_placeholder (tree tmpl)
return t;
}
+/* True iff T is a C++17 class template deduction placeholder. */
+
+bool
+template_placeholder_p (tree t)
+{
+ return is_auto (t) && CLASS_PLACEHOLDER_TEMPLATE (t);
+}
+
/* Make a "constrained auto" type-specifier. This is an
auto type with constraints that must be associated after
deduction. The constraint is formed from the given
diff --git a/gcc/testsuite/g++.dg/parse/template28.C b/gcc/testsuite/g++.dg/parse/template28.C
new file mode 100644
index 0000000..6868bc8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/template28.C
@@ -0,0 +1,10 @@
+// PR c++/79056
+
+template<class> struct A {};
+
+template<class T> void foo(A<T>=A<T>()) {} // { dg-error "" }
+
+void bar()
+{
+ foo(A<int>()); // { dg-error "" }
+}
reply other threads:[~2017-06-23 23:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=CADzB+2mp0t4NxNSQmWeZnW19u_cL6an7evXSonc0Kmt-UT+Xog@mail.gmail.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/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).