From patchwork Sat Feb 11 17:29:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 726868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vLJjD4k5gz9s74 for ; Sun, 12 Feb 2017 04:29:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="BoX5bn7r"; dkim-atps=neutral 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=dr+l7ZkiU5Dgakzj54xsBodEj9bwU4Gk0whLgf1rakh0eO ZibBdcrBuqMKC7j9JanO8vwuD0FcsSqmwDd8oi324aBeuyUhISkTia5vttb1YTQj DDbCOJ9ws5CyCMB9rmJ5Aehwb8T9YoJtiiHJA78ELSaYO4kGYcAbu9LVmKIhY= 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=rMd9bwsUHbEbUTzn3yjRVlK6yzA=; b=BoX5bn7rry9A+tiIUVom PNm5dbbHAfMLv9MSX6+yo/q+zp/ocm0hmQe4lMkoXwpNXGyxPgluK/RIx3im97Na UBYD3yJfD6VOTGO5Cosk5sniQoJRG8fPdh7KjhH/Mr9iLrTv3ew4/E0Ve4wRgRoz zWvf/Hwa4KcGuixsrD/cx8s= Received: (qmail 21098 invoked by alias); 11 Feb 2017 17:29:40 -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 21081 invoked by uid 89); 11 Feb 2017 17:29:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=Complain, Hx-languages-length:4129, U*jason, jasonredhatcom X-HELO: mail-ot0-f175.google.com Received: from mail-ot0-f175.google.com (HELO mail-ot0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 11 Feb 2017 17:29:38 +0000 Received: by mail-ot0-f175.google.com with SMTP id 65so47563056otq.2 for ; Sat, 11 Feb 2017 09:29:38 -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=fMPfeJM6EmPkxCVBgkg4S7CEf2dETzR5UHOYSntZuUU=; b=jJYb0xS1Yzai94qCmBAPaZjpQ62t+CGksJ0vzlELQeKYgjlAF3uyS/hRc0bs+jqmu/ 7EQ1EHQFPtgOGT72G6+OEc+RaFHd1L3p8lx7zVlOsY/dulyJu7bpYihfBZvH7Q1pTTx0 NtMzehCv9CZ2drVDuLntVOU8/3Zl2m5wsC+uPtNXR4I6pDmrEVCPfEW9WzUMSfJy+OGT tz+XZ4vNrfF7QKfUJj/zQNWx19B9YrNehfA86KxSyVLx1jSfsFMNpncAyBHUO00LBosd icIedSs5HesT1yA5drIbX7V53+HUPWfktEOxagxICLaAbpAT+7aujCfzuSa79vMnpwK7 Ke6Q== X-Gm-Message-State: AMke39kYYlWgZEFJXmgX+Ihc/vMxDkrbc7aQx6kbB7VCdHoiWQ1LcbL5Q9MKeSKfIufRxjX4w2g3dLr7KRDqDSzW X-Received: by 10.157.52.66 with SMTP id v60mr7837655otb.61.1486834177095; Sat, 11 Feb 2017 09:29:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.128.198 with HTTP; Sat, 11 Feb 2017 09:29:16 -0800 (PST) From: Jason Merrill Date: Sat, 11 Feb 2017 12:29:16 -0500 Message-ID: Subject: C++ PATCH for c++/77790 (ICE with auto function in C++11 mode) To: gcc-patches List X-IsSubscribed: yes We were complaining about a function with deduced return type in C++11 mode, but leaving it alone and then assuming it couldn't have happened later. Fixed by removing that assumption. Tested x86_64-pc-linux-gnu, applying to trunk. commit 94709718a2b25596677385adbf8a298c621ff8d0 Author: Jason Merrill Date: Fri Feb 10 15:40:21 2017 -0500 PR c++/77790 - ICE with auto function in C++11 mode * decl.c (undeduced_auto_decl): Remove C++14 limitation. (require_deduced_type): Add complain parm, return bool. * cp-tree.h: Adjust. * decl2.c (mark_used): Use require_deduced_type. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a410926..0146332 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5909,7 +5909,7 @@ extern tree reshape_init (tree, tree, tsubst_flags_t); extern tree next_initializable_field (tree); extern tree fndecl_declared_return_type (tree); extern bool undeduced_auto_decl (tree); -extern void require_deduced_type (tree); +extern bool require_deduced_type (tree, tsubst_flags_t = tf_warning_or_error); extern tree finish_case_label (location_t, tree, tree); extern tree cxx_maybe_build_cleanup (tree, tsubst_flags_t); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 734a6c7..2292a3a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -16138,24 +16138,29 @@ fndecl_declared_return_type (tree fn) return TREE_TYPE (TREE_TYPE (fn)); } -/* Returns true iff DECL was declared with an auto return type and it has +/* Returns true iff DECL was declared with an auto type and it has not yet been deduced to a real type. */ bool undeduced_auto_decl (tree decl) { - if (cxx_dialect < cxx14) + if (cxx_dialect < cxx11) return false; return type_uses_auto (TREE_TYPE (decl)); } /* Complain if DECL has an undeduced return type. */ -void -require_deduced_type (tree decl) +bool +require_deduced_type (tree decl, tsubst_flags_t complain) { if (undeduced_auto_decl (decl)) - error ("use of %qD before deduction of %", decl); + { + if (complain & tf_error) + error ("use of %qD before deduction of %", decl); + return false; + } + return true; } #include "gt-cp-decl.h" diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index cecb6a1..efc0b0e 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5084,12 +5084,9 @@ mark_used (tree decl, tsubst_flags_t complain) || DECL_LANG_SPECIFIC (decl) == NULL || DECL_THUNK_P (decl)) { - if (!processing_template_decl && type_uses_auto (TREE_TYPE (decl))) - { - if (complain & tf_error) - error ("use of %qD before deduction of %", decl); - return false; - } + if (!processing_template_decl + && !require_deduced_type (decl, complain)) + return false; return true; } @@ -5117,12 +5114,8 @@ mark_used (tree decl, tsubst_flags_t complain) && uses_template_parms (DECL_TI_ARGS (decl))) return true; - if (undeduced_auto_decl (decl)) - { - if (complain & tf_error) - error ("use of %qD before deduction of %", decl); - return false; - } + if (!require_deduced_type (decl, complain)) + return false; /* If we don't need a value, then we don't need to synthesize DECL. */ if (cp_unevaluated_operand || in_discarded_stmt) diff --git a/gcc/testsuite/g++.dg/cpp0x/auto41.C b/gcc/testsuite/g++.dg/cpp0x/auto41.C index b1551e2..a1065af 100644 --- a/gcc/testsuite/g++.dg/cpp0x/auto41.C +++ b/gcc/testsuite/g++.dg/cpp0x/auto41.C @@ -2,4 +2,4 @@ // { dg-do compile { target c++11 } } auto foo(); // { dg-error "auto" "" { target { ! c++14 } } } -auto fp = foo; // { dg-error "auto" "" { target c++14 } } +auto fp = foo; // { dg-error "auto" } diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn35.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn35.C new file mode 100644 index 0000000..a408174 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn35.C @@ -0,0 +1,11 @@ +// PR c++/77790 +// { dg-do compile { target c++11 } } + +template < typename S > struct A +{ + // { dg-error "" "" { target c++11_only } .+1 } + template < typename T > static auto f () { return 0; } + template < class U = decltype (f < S > ()) > int g () { return 0; } +}; + +auto a = A < int > {}.g ();