From patchwork Mon Dec 19 13:09:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 88467 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1147080qgi; Mon, 19 Dec 2016 05:09:50 -0800 (PST) X-Received: by 10.98.0.143 with SMTP id 137mr15025383pfa.183.1482152990410; Mon, 19 Dec 2016 05:09:50 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l5si6159238pgo.10.2016.12.19.05.09.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Dec 2016 05:09:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444724-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444724-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444724-patch=linaro.org@gcc.gnu.org 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=djQ5yiWZsorkSQThPDpFsIT2hEn58k1vxVvIHU1v/u4qUXWhGj ZHiYn8iqqmyV3fS/26GDuLkvMJ+UzyEeBG00LXg2DPfM8H/jlB4N3mbxjLIxZwBa dYPQ8UhH7y9kR+5Me7d2UqNxCAk7gIQSmEAEfy/M6TY/RqokDEd6OZ4Ak= 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=YO1G3lwSQVdgXuS6Y/ZqXbOEuZ0=; b=mzYnAeJ9S4jSLifp00fc m9wswmEarCnmByKcvXGrboXtZFmNhdCZK6tOLKb5LfptD7l7pelH9f5NjKZfB1ko cgV2Vo0OVTsd0Nlfo8VWYlDqDISFpXXQrl8xrTjsFNEpoCDvI7rHkN8Dmk5wBiKk WZ0XY6Sx+Ckb/wHkqRS7ZeQ= Received: (qmail 52767 invoked by alias); 19 Dec 2016 13:09:37 -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 52249 invoked by uid 89); 19 Dec 2016 13:09:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=tmpl, validity, viable, gcc_unreachable X-HELO: mail-yw0-f194.google.com Received: from mail-yw0-f194.google.com (HELO mail-yw0-f194.google.com) (209.85.161.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Dec 2016 13:09:25 +0000 Received: by mail-yw0-f194.google.com with SMTP id s68so8642808ywg.0 for ; Mon, 19 Dec 2016 05:09:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=7zwfuLC5XkewqZ1RGosx6ccSUSXKdd0RwnDLQCyUReg=; b=rCt6AuMYj6IHLpHZ5St9OFgVvGgvIrwU2wabSV7zOUPX2WM2U4UPYjLMHTVAF/liUn yVZuhrvzpb3Cu5J5le/VGGCu1faY1W+okO83PyVjJSx9rg19Iwd/JwZxcVSRf+Z8+I+e 7w6/8dXMZF4BPZWKgqnGxB62b69RaAwRxrOQANqFTMTI4RpoCR5tCnuWurNmHHZHkTyI 5DhA1rWTl/sFytUn9fAe34CMAbh/T/4u+07zrAZw8DB+DSr8zzEHCiBI6Pu0Ro+oDoFz qh4ih5F0yzSKYgapAlOk6iuseTmZjIhnEqR7Bd5ayS9IaH+m8j7K6WWKAeK5srRYicgS Sp/Q== X-Gm-Message-State: AIkVDXLVfB1UcipPzecRFPDrUNmIURhUfnunet4In5HYj0qWH8zjXocAjjwWKTCzyBTZhw== X-Received: by 10.13.234.19 with SMTP id t19mr19638ywe.204.1482152964089; Mon, 19 Dec 2016 05:09:24 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::9:e608]) by smtp.googlemail.com with ESMTPSA id a125sm7601461ywg.29.2016.12.19.05.09.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Dec 2016 05:09:23 -0800 (PST) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [PATCH] c++/78771 ICE with inheriting ctor Message-ID: <98daf7d1-8d37-6f96-8e91-a5310bb07657@acm.org> Date: Mon, 19 Dec 2016 08:09:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Jason, this patch fixes 78771, were an assert fires due to recursive instantiation of an inheriting ctor. Normally when a recursive instantiation is needed, we've already constructed and registered the declaration, so simply return it. For ctors though we need to construct the clones after we've instantiated the the master pattern (later in instantiate_template_1). Hence any recursive instantiation of a cloned fn will barf, as we do. Now, with an inherited ctor we have to deduce its exception spec and deletedness (deduce_inheriting_ctor). That's fine, until one gets the perverse testcase here. In figuring out what Middle ctor is needed by Middle(0), we end up trying to instantiate Derived::Derived (int) to see if Middle::Middle (Derived) is a viable candidate. And that's the recursion, as Derived::Derived inherits from Middle::Middle. Fixed by checking if the cloned instantiations actually exist before looking for them. I think the only case this can occur is when SPEC is an inherited ctor, hence the assert. Also, I don't think this can get us the wrong exept spec and deletedness -- it will be other (member) ctors that could change it, and we reconstruct the clones later anyway in the usual path. (I tried creating the clones earlier, immediately after construction and registering the main function, but that didn't work) ok? nathan -- Nathan Sidwell 2016-12-19 Nathan Sidwell PR c++/78771 * pt.c (instantiate_template_1): Check for recursive instantiation of inheriting constructor. PR c++/78771 * g++.dg/cpp0x/pr78771.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 243746) +++ cp/pt.c (working copy) @@ -17717,10 +17717,22 @@ instantiate_template_1 (tree tmpl, tree if (spec == error_mark_node) return error_mark_node; + /* If this is an inherited ctor, we can recursively clone it + when deducing the validity of the ctor. But we won't have + cloned the function yet, so do it now. We'll redo this + later, but any recursive information learnt here can't + change the validity. */ + if (!TREE_CHAIN (spec)) + { + gcc_assert (DECL_INHERITED_CTOR (spec)); + clone_function_decl (spec, /*update_method_vec_p=*/0); + } + /* Look for the clone. */ FOR_EACH_CLONE (clone, spec) if (DECL_NAME (clone) == DECL_NAME (tmpl)) return clone; + /* We should always have found the clone by now. */ gcc_unreachable (); return NULL_TREE; Index: testsuite/g++.dg/cpp0x/pr78771.C =================================================================== --- testsuite/g++.dg/cpp0x/pr78771.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr78771.C (working copy) @@ -0,0 +1,27 @@ +// PR c++/78771 +// { dg-do compile { target c++11 } } + +// ICE instantiating a deleted inherited ctor + +struct Base +{ + template Base (U); + + Base (int); +}; + +struct Derived; + +struct Middle : Base +{ + using Base::Base; + + Middle (Derived); +}; + +struct Derived : Middle +{ + using Middle::Middle; +}; + +Middle::Middle (Derived) : Middle (0) {}