From patchwork Thu May 17 14:23:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 915470 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-477866-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="ava0EpnF"; 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 40mtpP0CqBz9s4Y for ; Fri, 18 May 2018 00:23:55 +1000 (AEST) 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=x4BV60o5L+iqn5s15z8Q0o8j1JK5kPMVwPtNR2hKVNKGnk6/Px QY2kW4l1N70lnncVMIj6t6KwG6qD9H9PJFM8YOIf4Y1SvFz56+kU0Rt9mULue+iI GqB0QCtDFGkI/KaUjrOENh9QWKcgeDbMPJ71nOn3Zhqn9O5tSetmmQEcY= 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=0W0Lp0QiXdS2mSTpgpbx/6WcgWE=; b=ava0EpnFUMn0SLc/MmIF 3MdEwkv3AsB1xtxdujlIYeLuDsHhkYLQvIz9UL4JYkwHG8s6QJiACV/ikA/E+LYn fhQQRoK1GdXs7FLiIuSlr1kMKdN3JcdpLHW6nG0PNZaluLBXikSRAfCBdmsht0di loPEvzR8Fqw+4UxUFE2xZm8= Received: (qmail 52756 invoked by alias); 17 May 2018 14:23:48 -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 52745 invoked by uid 89); 17 May 2018 14:23:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=defective, 84588, sk:abort_f X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 May 2018 14:23:45 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4HELKwA175926; Thu, 17 May 2018 14:23:43 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2hx29whf65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 May 2018 14:23:43 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4HENgtQ030844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 May 2018 14:23:42 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4HENfPn005187; Thu, 17 May 2018 14:23:41 GMT Received: from [192.168.1.4] (/95.235.218.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 May 2018 07:23:40 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: =?utf-8?q?=5BC++_Patch=5D_PR_84588_=28=22=5B8_Regression=5D_inte?= =?utf-8?q?rnal_compiler_error=3A_Segmentation_fault_=28contains=5F?= =?utf-8?b?c3RydWN0X2NoZWNrKCkpIinigIsgKFRha2UgMik=?= Message-ID: Date: Thu, 17 May 2018 16:23:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8895 signatures=668698 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-1805170132 X-IsSubscribed: yes Hi, thus I had to revert my first try, when it caused c++/85713. I added two testcases for the latter (the second one covering what I learned from yet another defective try which I attached to the trail of c++/84588 yesterday) and finally figured out that the problem was that I was incorrectly calling abort_fully_implicit_template while tentatively parsing (if you look at the new lambda-generic-85713.C, that made impossible correctly parsing 'auto (&array) [5]' as second lambda parameter). Anyway, a few days ago, while looking for a completely different solution and comparing to other compilers too, I noticed that, more generally, we were missing a check in cp_parser_condition that we aren't declaring a function type when we are sure that we are handling a declaration: simply adding such a check covers as a special case c++/84588 too, and, being the check in cp_parser_condition, it automatically covers variants for conditions elsewhere, eg, for, while loops: with the patchlet below we handle all of them very similarly to clang and icc. Tested x86_64-linux. Thanks, Paolo. ////////////////////////////// /cp 2018-05-17 Paolo Carlini PR c++/84588 * parser.c (cp_parser_condition): Reject a declaration of a function type. /testsuite 2018-05-17 Paolo Carlini PR c++/84588 * g++.dg/cpp1y/pr84588.C: New. * g++.old-deja/g++.jason/cond.C: Adjust. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 260308) +++ cp/parser.c (working copy) @@ -11571,6 +11571,7 @@ cp_parser_condition (cp_parser* parser) tree attributes; cp_declarator *declarator; tree initializer = NULL_TREE; + location_t loc = cp_lexer_peek_token (parser->lexer)->location; /* Parse the declarator. */ declarator = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED, @@ -11597,15 +11598,23 @@ cp_parser_condition (cp_parser* parser) for sure. */ if (cp_parser_parse_definitely (parser)) { - tree pushed_scope; + tree pushed_scope = NULL_TREE; bool non_constant_p; int flags = LOOKUP_ONLYCONVERTING; /* Create the declaration. */ - decl = start_decl (declarator, &type_specifiers, - /*initialized_p=*/true, - attributes, /*prefix_attributes=*/NULL_TREE, - &pushed_scope); + if (declarator->kind == cdk_function) + { + error_at (loc, "a function type is not allowed here"); + if (parser->fully_implicit_function_template_p) + abort_fully_implicit_template (parser); + decl = error_mark_node; + } + else + decl = start_decl (declarator, &type_specifiers, + /*initialized_p=*/true, + attributes, /*prefix_attributes=*/NULL_TREE, + &pushed_scope); /* Parse the initializer. */ if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) Index: testsuite/g++.dg/cpp1y/pr84588.C =================================================================== --- testsuite/g++.dg/cpp1y/pr84588.C (nonexistent) +++ testsuite/g++.dg/cpp1y/pr84588.C (working copy) @@ -0,0 +1,25 @@ +// { dg-do compile { target c++14 } } + +struct a { + void b() {} + void c(void (*) () = [] { + if (a a(int auto) {}) // { dg-error "two or more data types|function type" } + ; + }) {} +}; + +struct d { + void e() {} + void f(void (*) () = [] { + for (;d d(int auto) {};) // { dg-error "two or more data types|function type" } + ; + }) {} +}; + +struct g { + void h() {} + void i(void (*) () = [] { + while (g g(int auto) {}) // { dg-error "two or more data types|function type" } + ; + }) {} +}; Index: testsuite/g++.old-deja/g++.jason/cond.C =================================================================== --- testsuite/g++.old-deja/g++.jason/cond.C (revision 260308) +++ testsuite/g++.old-deja/g++.jason/cond.C (working copy) @@ -47,8 +47,7 @@ int main() if (struct B * foo = new B) ; - if (int f () = 1) // { dg-warning "extern" "extern" } - // { dg-error "is initialized like a variable" "var" { target *-*-* } .-1 } + if (int f () = 1) // { dg-error "function type" } ; if (int a[2] = {1, 2}) // { dg-error "extended init" "" { target { ! c++11 } } }