From patchwork Fri Mar 9 03:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 883456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-474478-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fxY/nh/x"; dkim-atps=neutral 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 3zyDCP0TFzz9scZ for ; Fri, 9 Mar 2018 14:59:12 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=hIqo6ariXG2xbAlKkO4mXnig2R9GeROCWD++1HjxjNjdpGPcEZ IMcie/CYx+0pyFIPwE7ZdqIR5QGWQAc6gmTU4n1qq0uEMLAh7NDnZ1SQgKK3ibc0 OwWCky8G2auVBIWRly4PiSRhh0e7GohSIwhOMkQd3O+M8mjGdcuPNBqJo= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=wt48uKZihuUOpZ2Tn1wPypa1G3U=; b=fxY/nh/xwQdCELoIeYhr 8h4FF8iv7zj9MNPHvTrXBb9+RfyHTx17Jp6ZSGZVShln4crbEZEh4RPjiQLAd/mu NWOykNmZYA4+4ZEvNgz+Rjx7szjFboArYeR+79RwihpkqSChQwdaNT6f4PHEnM1/ awy12OUEjnDNr91Q/UgldLw= Received: (qmail 37707 invoked by alias); 9 Mar 2018 03:59:05 -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 37696 invoked by uid 89); 9 Mar 2018 03:59:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=eh X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Mar 2018 03:59:03 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w293vNDg088254; Fri, 9 Mar 2018 03:58:59 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2gkjqcr13d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Mar 2018 03:58:59 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w293uLvm025240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Mar 2018 03:56:21 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w293uKeD019910; Fri, 9 Mar 2018 03:56:20 GMT Received: from [192.168.1.4] (/80.116.189.199) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 08 Mar 2018 19:56:19 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 71169 ("[7/8 Regression] ICE on invalid C++ code in pop_nested_class"), PR 71832 and more (Take 2) Message-ID: Date: Fri, 9 Mar 2018 04:56:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8826 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803090049 X-IsSubscribed: yes Hi again, eventually I'm back with sort-of a synthesis of the various ideas, thus something I believe very close in spirit to my original RFC, but much more direct, using CLASSTYPE_TI_ARGS (eh!) and Jason' helper. And I managed to see that we want to vec_safe_truncate the unparsed entities - better late than never. Anyway, another round of testing is in progress (in v3), all good so far. Cheers, Paolo. //////////////////// /cp 2018-03-09 Jason Merrill Paolo Carlini PR c++/71169 PR c++/71832 * pt.c (any_erroneous_template_args_p): New. * cp-tree.h (any_erroneous_template_args_p): Declare it. * parser.c (cp_parser_class_specifier_1): Use it. /testsuite 2018-03-09 Jason Merrill Paolo Carlini PR c++/71169 PR c++/71832 * g++.dg/cpp0x/pr71169.C: New. * g++.dg/cpp0x/pr71169-2.C: Likewise. * g++.dg/cpp0x/pr71832.C: Likewise. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 258378) +++ cp/cp-tree.h (working copy) @@ -6558,6 +6558,7 @@ extern int processing_template_parmlist; extern bool dependent_type_p (tree); extern bool dependent_scope_p (tree); extern bool any_dependent_template_arguments_p (const_tree); +extern bool any_erroneous_template_args_p (const_tree); extern bool dependent_template_p (tree); extern bool dependent_template_id_p (tree, tree); extern bool type_dependent_expression_p (tree); Index: cp/parser.c =================================================================== --- cp/parser.c (revision 258378) +++ cp/parser.c (working copy) @@ -22669,6 +22669,19 @@ cp_parser_class_specifier_1 (cp_parser* parser) cp_default_arg_entry *e; tree save_ccp, save_ccr; + if (type != error_mark_node + && CLASSTYPE_TEMPLATE_INFO (type) + && any_erroneous_template_args_p (CLASSTYPE_TI_ARGS (type))) + { + /* Skip default arguments, NSDMIs, etc, in order to improve + error recovery (c++/71169, c++/71832). */ + vec_safe_truncate (unparsed_funs_with_default_args, 0); + vec_safe_truncate (unparsed_nsdmis, 0); + vec_safe_truncate (unparsed_classes, 0); + vec_safe_truncate (unparsed_funs_with_definitions, 0); + goto out; + } + /* In a first pass, parse default arguments to the functions. Then, in a second pass, parse the bodies of the functions. This two-phased approach handles cases like: @@ -22745,6 +22758,7 @@ cp_parser_class_specifier_1 (cp_parser* parser) else vec_safe_push (unparsed_classes, type); + out: /* Put back any saved access checks. */ pop_deferring_access_checks (); Index: cp/pt.c =================================================================== --- cp/pt.c (revision 258378) +++ cp/pt.c (working copy) @@ -25048,6 +25048,38 @@ any_dependent_template_arguments_p (const_tree arg return false; } +/* Returns true if ARGS contains any errors. */ + +bool +any_erroneous_template_args_p (const_tree args) +{ + int i; + int j; + + if (args && TREE_CODE (args) != TREE_VEC) + { + if (tree ti = get_template_info (args)) + args = TI_ARGS (ti); + else + args = NULL_TREE; + } + + if (!args) + return false; + if (args == error_mark_node) + return true; + + for (i = 0; i < TMPL_ARGS_DEPTH (args); ++i) + { + const_tree level = TMPL_ARGS_LEVEL (args, i + 1); + for (j = 0; j < TREE_VEC_LENGTH (level); ++j) + if (error_operand_p (TREE_VEC_ELT (level, j))) + return true; + } + + return false; +} + /* Returns TRUE if the template TMPL is type-dependent. */ bool Index: testsuite/g++.dg/cpp0x/pr71169-2.C =================================================================== --- testsuite/g++.dg/cpp0x/pr71169-2.C (nonexistent) +++ testsuite/g++.dg/cpp0x/pr71169-2.C (working copy) @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +template class A { // { dg-error "declared" } + template void m_fn1() { + m_fn1(); + } +}; + +template +struct B +{ + int f(int = 0) { return 0; } +}; + +int main() +{ + B b; + return b.f(); +} Index: testsuite/g++.dg/cpp0x/pr71169.C =================================================================== --- testsuite/g++.dg/cpp0x/pr71169.C (nonexistent) +++ testsuite/g++.dg/cpp0x/pr71169.C (working copy) @@ -0,0 +1,7 @@ +// { dg-do compile { target c++11 } } + +template class A { // { dg-error "declared" } + template void m_fn1() { + m_fn1(); + } +}; Index: testsuite/g++.dg/cpp0x/pr71832.C =================================================================== --- testsuite/g++.dg/cpp0x/pr71832.C (nonexistent) +++ testsuite/g++.dg/cpp0x/pr71832.C (working copy) @@ -0,0 +1,7 @@ +// { dg-do compile { target c++11 } } + +template < typename decltype (0) > struct A // { dg-error "expected|two or more" } +{ + void foo () { baz (); } + template < typename ... S > void baz () {} +};