From patchwork Fri Jun 23 23:30:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 780312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wvZTd4pf6z9s74 for ; Sat, 24 Jun 2017 09:31:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yqBKOoqR"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=ymK0xQREViWU6Zsoz3zU3dsF8l1hlRDECzyzgmpovfmbGD MixhdIryZQgU9EOj94aCX/Om3QBs6zL5419uogeakWxOZ3Y7iyh8hQEUa5WARVCe /UlUQj2n6FojvE7+j7FE04bFoA6b/gUskqXjWzymY5hL5tnzb6M5krKncrZsA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=d66Y1PYTrkM9IYKq+L/fufVf69s=; b=yqBKOoqRVNY4KBlggk8K jNnKhZSuJiB3mMQdI4ZOrPM2nVxa7cHEIlUKZA7hauew325mmSpxbqVbqejXqQ0z uEGiuERbMfnwFvy7FeWHFkwuGWtmBqX5qIq1ol0YzjbfPfZbCMjrO+FXHjln1BP2 rA4LJDK/dSRp3PCUZK5mfcQ= Received: (qmail 82110 invoked by alias); 23 Jun 2017 23:31:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 82020 invoked by uid 89); 23 Jun 2017 23:31:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=our X-HELO: mail-it0-f43.google.com Received: from mail-it0-f43.google.com (HELO mail-it0-f43.google.com) (209.85.214.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 23 Jun 2017 23:31:15 +0000 Received: by mail-it0-f43.google.com with SMTP id b205so15372823itg.1 for ; Fri, 23 Jun 2017 16:31:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=dt4ac9Gyc435EtTGfJe7sw2IDtchHJNJD+zIl3f3iOc=; b=MM7PC2PQo1yqYv/EUwtuutiF4oCJK7qIXsrCOIpHx2uyxiVrdDY7NZNvuIB3LCTT5Y PuDU0LCqBUin5Nmz6qo2ZKr9bacJ2JvyVS76bj/ocj4lQnXsQDG8+RKuk0E23j7DvXeX pf8LR+AcfnQYhfWYLxfIt9HWvAYMV1lZMXlDnRSak9r9bBuwfpilsOC1l4yfhBx3E31f BfyA+VYnIpsFosd6cCWrKuXlZWUDpacxaQJ6+QWyFLfUfIYRjc47yqbs8IeAnQfg478K Bw00Niw0F+QNSknjen5gxcQ7oXLVpNGNgCCEadP9CJ5WiU3GNyFZgd6fRrnXQKVwb0GO 9hEQ== X-Gm-Message-State: AKS2vOyyD6QNCZd3AE4Okra0PlZs/dknHz1Pamf9EzmvlqA5XyOoE49m yLgwdX8asZ2j28QfYqgwkS7J15Zl5MEWObA= X-Received: by 10.36.76.22 with SMTP id a22mr9748375itb.83.1498260673701; Fri, 23 Jun 2017 16:31:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.20.139 with HTTP; Fri, 23 Jun 2017 16:30:53 -0700 (PDT) From: Jason Merrill Date: Fri, 23 Jun 2017 19:30:53 -0400 Message-ID: Subject: C++ PATCH for c++/79056, C++17 ICE with invalid template-id To: gcc-patches List X-IsSubscribed: yes 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. commit bbea244e8042460d49970b7fffce13f79e58d8e9 Author: Jason Merrill 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 struct A {}; + +template void foo(A=A()) {} // { dg-error "" } + +void bar() +{ + foo(A()); // { dg-error "" } +}