From patchwork Wed Jan 24 15:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 865389 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-471961-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="j/b8JsHa"; 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 3zRVMS0QBTz9s7s for ; Thu, 25 Jan 2018 03:03:30 +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=gsLzKyH6PIdntM38bKS9p4Cb+HXA2jLmM0dPIyTvqTTYO0ykDp xXUCOt74H7JRKVt8UyEZCjWubeI4ADXbSSO8NED9WYPWJuERlyaCe+QosuH7+Mgj N5KM2gvoySEhepYc0lU4lqkNJqfdhLbvIi1iA0+UQdjs68ifMlVdNptb4= 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=ITSYxHejBpCCG/rlOXR1GvBQtks=; b=j/b8JsHa4zmKkiXFkCbY SpAR61Jfroaamz3wFQ0fFmbUazCnRLHrhDGEgHZ1pSs3tf+iuH9Q0SAAxcpzqwxF ozxwyL80wwoie/2ijkUb7brmGygrf56sIzkWSDoSWy/VAY5NFxWf0f+hK8FXFmNB FApVPaRIxLdUHskFEVNribQ= Received: (qmail 82069 invoked by alias); 24 Jan 2018 16:03:23 -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 82058 invoked by uid 89); 24 Jan 2018 16:03:23 -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, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2256, jasons, jason's, mild 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; Wed, 24 Jan 2018 16:03:21 +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 w0OG23Or064726; Wed, 24 Jan 2018 16:03:16 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2fpvwyg7ke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2018 16:03:16 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0OFwGxE016189 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 24 Jan 2018 15:58:16 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0OFwEcS020747; Wed, 24 Jan 2018 15:58:14 GMT Received: from [192.168.1.4] (/79.33.231.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Jan 2018 07:58:13 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch/RFC] PR 83796 ("[6/7/8 Regression] Abstract classes allowed to be instantiated when initialised as default parameter to function or constructor") Message-ID: Date: Wed, 24 Jan 2018 16:58:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8783 signatures=668655 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-1801240214 X-IsSubscribed: yes Hi, I'm looking into this rather mild regression, which should be relatively easy to fix. In short, Jason's fix for c++/54325 moved an abstract_virtuals_error_sfinae check from build_aggr_init_expr to build_cplus_new therefore the testcase in this new bug isn't rejected anymore because a special conditional for value-initialization from { } in convert_like_real simply calls build_value_init and quickly returns, thus build_cplus_new isn't involved. Thus I'm working on the best way to add back the check. The below, which also uses cp_unevaluated_operand, appears to work. Likewise something similar inside build_value_init itself, which however seems too generic to me (build_value_init is called in many other cases). I'm also not sure about cp_unevaluated_operand, whether we need something more precise. Thanks! Paolo. ////////////////////// Index: cp/call.c =================================================================== --- cp/call.c (revision 257013) +++ cp/call.c (working copy) @@ -6765,6 +6765,9 @@ convert_like_real (conversion *convs, tree expr, t && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)) { bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr); + if (cp_unevaluated_operand + && abstract_virtuals_error_sfinae (NULL_TREE, totype, complain)) + return error_mark_node; expr = build_value_init (totype, complain); expr = get_target_expr_sfinae (expr, complain); if (expr != error_mark_node) Index: testsuite/g++.dg/cpp0x/abstract-default1.C =================================================================== --- testsuite/g++.dg/cpp0x/abstract-default1.C (nonexistent) +++ testsuite/g++.dg/cpp0x/abstract-default1.C (working copy) @@ -0,0 +1,26 @@ +// PR c++/83796 +// { dg-do compile { target c++11 } } + +struct MyAbstractClass +{ + virtual int foo() const = 0; +}; + +struct TestClass +{ + TestClass(const MyAbstractClass& m = {}) // { dg-error "abstract type" } + : value_(m.foo()) {} + + int value_; +}; + +int TestFunction(const MyAbstractClass& m = {}) // { dg-error "abstract type" } +{ + return m.foo(); +} + +int main() +{ + TestClass testInstance; + TestFunction(); +}