From patchwork Fri Feb 9 21:01:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 871568 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-472985-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="h5+8qjus"; 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 3zdSDL5nszz9s7M for ; Sat, 10 Feb 2018 08:01:53 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=UuvYiEmBiJSAel/5ZRvVKcn58TJcHrRKZ/CCExcs9QKSmN +nPr5W2AwqShoqfcQeQBXCQdyDj/wpoB0uZzhWU4cBouWUEo3Eeuq3v1PU8Ive8f lp1A+iSvx1Ys1BKLqCJwJ+CtjpNLBzYeRmydQfOgiKuoBB71atxdM/VLAU+1E= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=YUhIzrOgNfOLgg/iANV5AC4ZW9w=; b=h5+8qjusqw3Gk917jSAW NwwfdNbu5ieTqZmjzHkDBqyxPyZa5deFE2N90TS8rcwjlawrDCCijmUgjPEy+OMq V0Z/NMejNYLH1pN91TLOMbHEZtXh4c2ngsSD0oG5hCo/WRrG/CwP1wiFLu2AsWGC wO3JgTYcjHQAFHPrsSaDSeA= Received: (qmail 60656 invoked by alias); 9 Feb 2018 21:01:45 -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 60104 invoked by uid 89); 9 Feb 2018 21:01:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f178.google.com Received: from mail-io0-f178.google.com (HELO mail-io0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Feb 2018 21:01:43 +0000 Received: by mail-io0-f178.google.com with SMTP id p188so11070913ioe.12 for ; Fri, 09 Feb 2018 13:01:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NOUMSgakEKiLvMEkj36T+vTyMTLfayqIugjiTJPUOS0=; b=Hdvdgsyd41iiKJA0TydU3oD89kp7KjaWm/+sCNwSK2W1Kcww2Y/kqhbIbFg0FknxVI wc3bgJr9Xk20LlK0kzkYmFjR1yLly46hWZVFS1AB5MdKWJ7aMs6PdsUEb+iNdDD+rQVG a2IgGusRfYk54+FqiDJOZ5YT4JA592N/H8JzojrPHYgOxvTxL3OKia6IAQrMpH7W/k6N hUfC8wAh9/bZXhjF2jFo4JTGEBb8WW7KrtJzabz7daQDaUk85dhQVRdLHhhqjMkTllyJ rxcMCzx924Z5H/X/GLOgMmBaNUHa0s/F8Xcb9VxlkvreEQGhdMtOuvj+aDbsCSe96xJI P8MA== X-Gm-Message-State: APf1xPCYBq5v9P0w7TwihVudw/iAaC8Lc2jp/X31s1J2W8hVPgKZVEB8 Cxo45iZH+cLwpJfrDPZKrxjOnsPEQijouABJXcmEgNJM X-Google-Smtp-Source: AH8x2246oYgjT7gzanZDq8KVYyAop9F2tFkoAo6hTUO3AFlImLP1kA2KRB4cUZwuLaJ8U9qBiB8pkryRUNBKkbnwT8s= X-Received: by 10.107.133.75 with SMTP id h72mr4762372iod.227.1518210099874; Fri, 09 Feb 2018 13:01:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.17.206 with HTTP; Fri, 9 Feb 2018 13:01:19 -0800 (PST) From: Jason Merrill Date: Fri, 9 Feb 2018 16:01:19 -0500 Message-ID: Subject: C++ PATCH for c++/81917, ICE with self-referential partial specialization To: gcc-patches List X-IsSubscribed: yes In this testcase we were managing to instantiate the same class twice, leading to an ICE. Fixed by setting TYPE_BEING_DEFINED before we consider what partial specialization to use. This also causes several existing testcases to error about incomplete types rather than excess template instantiation depth, which seems appropriate. Tested x86_64-pc-linux-gnu, applying to trunk. commit 46063f6cb79e4f37040a326a2da1378e0e98cb38 Author: Jason Merrill Date: Fri Feb 9 14:26:03 2018 -0500 PR c++/81917 - ICE with void_t and partial specialization. * pt.c (instantiate_class_template_1): Set TYPE_BEING_DEFINED before calling most_specialized_partial_spec. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 9c57709e7a7..281604594ad 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10347,14 +10347,14 @@ instantiate_class_template_1 (tree type) templ = most_general_template (CLASSTYPE_TI_TEMPLATE (type)); gcc_assert (TREE_CODE (templ) == TEMPLATE_DECL); + /* Mark the type as in the process of being defined. */ + TYPE_BEING_DEFINED (type) = 1; + /* Determine what specialization of the original template to instantiate. */ t = most_specialized_partial_spec (type, tf_warning_or_error); if (t == error_mark_node) - { - TYPE_BEING_DEFINED (type) = 1; - return error_mark_node; - } + return error_mark_node; else if (t) { /* This TYPE is actually an instantiation of a partial @@ -10379,16 +10379,16 @@ instantiate_class_template_1 (tree type) /* If the template we're instantiating is incomplete, then clearly there's nothing we can do. */ if (!COMPLETE_TYPE_P (pattern)) - return type; + { + /* We can try again later. */ + TYPE_BEING_DEFINED (type) = 0; + return type; + } /* If we've recursively instantiated too many templates, stop. */ if (! push_tinst_level (type)) return type; - /* Now we're really doing the instantiation. Mark the type as in - the process of being defined. */ - TYPE_BEING_DEFINED (type) = 1; - /* We may be in the middle of deferred access check. Disable it now. */ push_deferring_access_checks (dk_no_deferred); diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-62.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-62.C new file mode 100644 index 00000000000..6f1fa4584ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-62.C @@ -0,0 +1,22 @@ +// PR c++/81917 +// { dg-do compile { target c++11 } } + +template using a = void; +template struct b +{ + typedef int c; +}; +template class b>; +template ::c> class f; +template class g { }; +template class h +{ + class i; + typedef g> j; + class i + { + j k; // { dg-error "incomplete" } + }; +}; +h H; + diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-template2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-template2.C index 40e3075c162..0df0d4e89c3 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist-template2.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-template2.C @@ -1,6 +1,5 @@ // PR c++/71747 // { dg-do compile { target c++11 } } -// { dg-options -ftemplate-depth=20 } template < bool > struct A { @@ -14,10 +13,8 @@ template < bool > struct A template < bool, typename = int > struct F; template < bool X > // should be: struct F < X, typename A < A < X > {} () >::type > -struct F < X, typename A < F < X > {} () >::type > // { dg-error "" } +struct F < X, typename A < F < X > {} () >::type > { }; -F < true > f; - -// { dg-prune-output "compilation terminated" } +F < true > f; // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/template/crash125.C b/gcc/testsuite/g++.dg/template/crash125.C index 448f74682d4..de41b99a927 100644 --- a/gcc/testsuite/g++.dg/template/crash125.C +++ b/gcc/testsuite/g++.dg/template/crash125.C @@ -13,6 +13,4 @@ struct TraitCheckImpl > { typedef void Complete; }; -Swappable s; // { dg-error "depth" } - -// { dg-prune-output "compilation terminated" } +Swappable s; // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/template/pr51488.C b/gcc/testsuite/g++.dg/template/pr51488.C index 4979a22787c..794a6cfe067 100644 --- a/gcc/testsuite/g++.dg/template/pr51488.C +++ b/gcc/testsuite/g++.dg/template/pr51488.C @@ -2,6 +2,4 @@ template struct s; template struct s::a> {}; -s ca; // { dg-error "depth" } - -// { dg-prune-output "compilation terminated" } +s ca; // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/template/pr55843.C b/gcc/testsuite/g++.dg/template/pr55843.C index 467dd827218..04079ed1175 100644 --- a/gcc/testsuite/g++.dg/template/pr55843.C +++ b/gcc/testsuite/g++.dg/template/pr55843.C @@ -1,5 +1,3 @@ -// { dg-options "-ftemplate-depth-8" } - template< typename T > struct type_wrapper { }; typedef char (&yes_tag)[2]; @@ -7,11 +5,11 @@ template struct if_c { }; template< typename T > struct has_type { struct gcc_3_2_wknd { - template< typename U > static yes_tag test( type_wrapper const volatile* // { dg-message "required" } + template< typename U > static yes_tag test( type_wrapper const volatile* // { dg-message "" } , type_wrapper* = 0 ); }; typedef type_wrapper t_; - static const bool value = sizeof(gcc_3_2_wknd::test(static_cast(0))) == // { dg-message "required" } + static const bool value = sizeof(gcc_3_2_wknd::test(static_cast(0))) == // { dg-message "" } sizeof(yes_tag); }; template struct Get_type { @@ -22,7 +20,4 @@ template struct Get_type >::value >::type> { }; // { dg-message "required" } template struct Get_type >::value >::type> { }; // { dg-message "required" } -typedef Get_type::type P; - -// { dg-prune-output "-ftemplate-depth" } -// { dg-prune-output "compilation terminated" } +typedef Get_type::type P; // { dg-message "" }