From patchwork Thu Nov 16 12:10:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 838523 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-466982-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="ZeLLERwC"; 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 3yd0T3255mz9t2R for ; Thu, 16 Nov 2017 23:11:03 +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=GkLNwB9HgrgG/BUAstB5FGDEpuDOAnf3462glrSd8/BO+QZJb4 siSGRNquGU8Bko81hxPY/KWaoKzN5gmWp/tZ1x5ESQrIT3Eybo1Ca7O/0zJYDDa6 1aD8FQWKjimurSd+LiOx3fp7U50Y/JfPJhyWbT42lrFUxPOh4rFyq9bgg= 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=eBNdFxmilByqIjJy4Ad5iYWflIo=; b=ZeLLERwCpvq0zPm/wA2a yS1VDBOgCz0ZB8qPOUmwXutPfbA9kFi2Jxcw3DxMN7Ad3dnrgXLdog3OCj914UgK mYX2kB1OT8c/5DKIUYRUc2DKAfAOJ6ib6ZAFmdhawBk+y/lZq2Wu0dyB21XSiDhy WOWFPdG1R+qgkNO+5ZYcUxs= Received: (qmail 17744 invoked by alias); 16 Nov 2017 12:10:54 -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 16136 invoked by uid 89); 16 Nov 2017 12:10:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:lambda- X-HELO: mail-io0-f175.google.com Received: from mail-io0-f175.google.com (HELO mail-io0-f175.google.com) (209.85.223.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Nov 2017 12:10:51 +0000 Received: by mail-io0-f175.google.com with SMTP id i38so5021837iod.2 for ; Thu, 16 Nov 2017 04:10:51 -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:content-language; bh=cZOmOWGTKbJ4lPok3Drj4TEDxyu/PqL8Jmw/Y32z7SM=; b=pJwVTC+a4kiS1VYeVNr1r4YYGnnMxauhQkSkU4VrK/ngjziStMPUpBeqsySSfgi35Q Xg6nOHYt0YLe/MUO2DKVMA8PMGdX4JHbbBAhJFPzAxioS8soY/EqvzC5R7uhczlk8+SE Jn+uV8KN8vkKhl4gbvy+76k9/oFcU6p2Zzk4MvzSLL4RjI5sL5klGXPmhGbreJEZ5RRS Xvp1ryPcKrjOeOVB8atpNvBqy7Xt5xarNCkrKQgdEGh1enlNbMcB2gcxgS5b+OvmYV1C G5thZlgily1oEbkB6LNnsv+NTifjHTel7McYpPyTHd2RRBvhNQhjaBFhrq46WnjBkP3X FQ7g== X-Gm-Message-State: AJaThX7TX8rEX0DEHp1qlOvQGLjJrEpwUALiC+Y10wP5vYvC5iv0Hb1c tLo4LbrYNTXo4nWq5LYGZ6U= X-Google-Smtp-Source: AGs4zMYLOPSRy5FSHa28Sc4Hs7iiJRuZO4SXqi4vlmITESjIYiZpFDbjfd5ootYcnd/yYSc7BS13Fw== X-Received: by 10.107.186.139 with SMTP id k133mr1436425iof.121.1510834250047; Thu, 16 Nov 2017 04:10:50 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c090:200::7:fd80]) by smtp.googlemail.com with ESMTPSA id i76sm732338itf.3.2017.11.16.04.10.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 04:10:49 -0800 (PST) To: GCC Patches Cc: Jason Merrill From: Nathan Sidwell Subject: [PR c++/81060] ICE with invalid initialzer via lambda Message-ID: <0944f774-e972-4e24-8820-fc02c08ce10e@acm.org> Date: Thu, 16 Nov 2017 07:10:45 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 This patch fixes a regression my name lookup changes caused earlier this year. We'd already emitted an error about a bogus template definition, but the fallout from that now killed us :( I restored some of the handling r247909 removed. Namely restoring the pushing of a lambda type into the scope enclosing an already-completed class. Interestingly, this caused lambda-template13.C to start complaining about a not-defined template needing instantiating on a local (lambda) class. That seems correct to me. function's ctor is instantiated for the default arg in: void C::foo (T, function = [] {}); Applying to trunk. nathan 2017-11-16 Nathan Sidwell PR c++/81060 * decl.c (xref_tag_1): Push lambda into current scope. * name-lookup.c (do_pushtag): Don't deal with ts_lambda here. PR c++81060 * g++.dg/cpp0x/lambda/lambda-template13.C: Avoid undefined template using local type error. * g++.dg/cpp0x/pr81060.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 254786) +++ cp/decl.c (working copy) @@ -13546,8 +13546,12 @@ xref_tag_1 (enum tag_types tag_code, tre t = make_class_type (code); TYPE_CONTEXT (t) = context; if (scope == ts_lambda) - /* Mark it as a lambda type. */ - CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node; + { + /* Mark it as a lambda type. */ + CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node; + /* And push it into current scope. */ + scope = ts_current; + } t = pushtag (name, t, scope); } } Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 254786) +++ cp/name-lookup.c (working copy) @@ -6242,9 +6242,7 @@ do_pushtag (tree name, tree type, tag_sc view of the language. */ || (b->kind == sk_template_parms && (b->explicit_spec_p || scope == ts_global)) - /* Pushing into a class is ok for lambdas or when we want current */ || (b->kind == sk_class - && scope != ts_lambda && (scope != ts_current /* We may be defining a new type in the initializer of a static member variable. We allow this when @@ -6267,7 +6265,6 @@ do_pushtag (tree name, tree type, tag_sc tree cs = current_scope (); if (scope == ts_current - || scope == ts_lambda || (cs && TREE_CODE (cs) == FUNCTION_DECL)) context = cs; else if (cs && TYPE_P (cs)) @@ -6304,8 +6301,7 @@ do_pushtag (tree name, tree type, tag_sc if (b->kind == sk_class) { - if (!TYPE_BEING_DEFINED (current_class_type) - && scope != ts_lambda) + if (!TYPE_BEING_DEFINED (current_class_type)) return error_mark_node; if (!PROCESSING_REAL_TEMPLATE_DECL_P ()) Index: testsuite/g++.dg/cpp0x/lambda/lambda-template13.C =================================================================== --- testsuite/g++.dg/cpp0x/lambda/lambda-template13.C (revision 254786) +++ testsuite/g++.dg/cpp0x/lambda/lambda-template13.C (working copy) @@ -4,7 +4,7 @@ struct function { template < typename _Functor> - function (_Functor); + function (_Functor) {} }; template Index: testsuite/g++.dg/cpp0x/pr81060.C =================================================================== --- testsuite/g++.dg/cpp0x/pr81060.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr81060.C (working copy) @@ -0,0 +1,11 @@ +// { dg-do compile { target c++11 } } +// PR 81050 ICE in invalid after error + +template struct A +{ + static const int i; +}; + +template +const int A::i // { dg-error "template definition of non-template" } += []{ return 0; }(); // BOOM!