From patchwork Sat Mar 10 11:57:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 884138 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-474538-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TF3IZzN+"; 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 3zz2nN613dz9tbS for ; Sat, 10 Mar 2018 22:58:00 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=vtvP0HWFwWOQvirvsMHTv0+FSKt1v60bGi8rGvtxyEJKHrKhs3zKw PckHDASA7NH5FHj3UHFPzZdhpuQLPf/5Mrl5hknd9znsPi7F+Ad/kL8zpABX4cd/ HxizvMAE9dMXb+11yshQOglFW1oZk/hqgIm8WPgK4Vv3WpwTYZmVi4= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=/0YD6Xrz11ViBVGYRIGdy8b/+yo=; b=TF3IZzN+a8pdy7J8TB+8 GQAHIliMaD0CncE+yl8iaR7oyBsx6plJjyEJmk2v6Ht0hca/G/IsviOZ0z9PiTqe sUVtgZc4T4tN5HjS9URDCUefXuh9vXGDLV2QePL8qNf8GjJ5V6g70f5/ayvm1xf4 IFGH9Js1RRPJm11UoNWIe+0= Received: (qmail 70485 invoked by alias); 10 Mar 2018 11:57:53 -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 70476 invoked by uid 89); 10 Mar 2018 11:57:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=amounting, vanish X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 10 Mar 2018 11:57:51 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5029881DE1 for ; Sat, 10 Mar 2018 11:57:50 +0000 (UTC) Received: from freie.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 147295C262 for ; Sat, 10 Mar 2018 11:57:49 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by freie.home (8.15.2/8.15.2) with ESMTP id w2ABvd0k366383; Sat, 10 Mar 2018 08:57:39 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PR c++/84647] undeclared fn called in auto default arg in ptr decl Date: Sat, 10 Mar 2018 08:57:39 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 We ICEd when attempting to convert a default arg for an auto parm, the default arg amounting to a call to an undeclared function, in a declaration of a pointer to function variable. It's all wrong, but because of the bogus implicit template, we accept the typeless expression at first. Later on, after we finish the implicit template because it's bogus (but deferring the reporting of the error to the end of cp_parser_init_declarator), no longer processing_template_decl, we attempt to perform the impossible conversion from NULL type to an unresolved and unresolvable type placeholder. We crash in implicit_conversion because FROM is NULL, and then (once we arrange to return a NULL conversion there) in perform_implicit_conversion_flags when trying to determine whether the expr is an invalid use of a nonstatic memfn. This patch makes implicit_conversion return NULL when the FROM type is NULL, and reports a proper error for typeless EXPRs in perform_implicit_conversion_flags. I considered testing for !processing_template_decl, but decided not to bother. FWIW, I'd tried temporarily incrementing processing_template_decl while completing the parsing of the bogus implicit template, but that didn't go very well: we'd skip the conversion all right, but start_decl would attempt to push_template_decl, and that would silently return error_mark_node, which would in turn silence the bogus implicit template error. With -fpermissive, all the other errors (misplaced auto, unexpected default arg in pointer declaration, and undeclared function call) would be turned to warnings or vanish altogether, so compilation would complete in spite of the bogus parsing and the failed template declaration. I decided not to explore that path further, and ended up working around the errors in the conversion, so as to make sure we'd get at least some error (we get all of them with the enclosed testcase). Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/84647 * call.c (implicit_conversion): Return NULL conv for NULL from type. (perform_implicit_conversion_flags): If conv is NULL, check for NULL expr type and report an error instead of ICEing. for gcc/testsuite/ChangeLog PR c++/84647 * g++.dg/cpp0x/pr84647.C: New. --- gcc/cp/call.c | 10 ++++++++++ gcc/testsuite/g++.dg/cpp0x/pr84647.C | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr84647.C diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 45c22aaa312c..cb95fe35891a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1836,6 +1836,9 @@ implicit_conversion (tree to, tree from, tree expr, bool c_cast_p, from = TREE_TYPE (expr); } + if (!from) + return NULL; + if (TREE_CODE (to) == REFERENCE_TYPE) conv = reference_binding (to, from, expr, c_cast_p, flags, complain); else @@ -10586,6 +10589,13 @@ perform_implicit_conversion_flags (tree type, tree expr, Call instantiate_type to get good error messages. */ if (TREE_TYPE (expr) == unknown_type_node) instantiate_type (type, expr, complain); + /* We may find this if we parse a default argument as part + of a bogus implicit template function declaration. It + might be a template-dependent expression, or a call of an + undeclared function. */ + else if (!TREE_TYPE (expr)) + error_at (loc, "cannot convert typeless expression %qE", + expr); else if (invalid_nonstatic_memfn_p (loc, expr, complain)) /* We gave an error. */; else diff --git a/gcc/testsuite/g++.dg/cpp0x/pr84647.C b/gcc/testsuite/g++.dg/cpp0x/pr84647.C new file mode 100644 index 000000000000..63292bd8f692 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr84647.C @@ -0,0 +1,3 @@ +// { dg-do compile { target c++11 } } + +void (*a)(auto b = c()); // { dg-error "parameter declaration|depend on a template|undeclared name|not declared|default arguments|typeless expression|implicit template" }