From patchwork Mon Feb 6 21:11:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 724736 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 3vHKt84Xbyz9s2P for ; Tue, 7 Feb 2017 08:12:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rVRS44CE"; 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=bisic67GNwJmAWJHm/8WKqsQDAkO6cxkisindet41GMSxz jhTCA00DwmDL/Qm37TvgJMGCeR7tDr8LAFKGoh5inxcc7fITJ71Q7br3tpI/QUJk V6FCFguZlotV+6EnZsA+3AYkhUDcOpu8f5obyQN6a+HquwxIhiGH3opnSARVI= 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=JR0yh5P+IdtTvVRAOBk5FX0rrY8=; b=rVRS44CEPBOatKDEb9ri mZglh8swsxClldE4DH9ZD+BYNpymUasXd7KvKyG8lCq3o+aFIX0rjEN3IYHhfxFu Wfbe0sviV195xFcdy12AvK3Sf81w2yeU/4V0myCh/+3NvwfflOUTvr4uDBpa9rSB 6VqvJlGa7R8odq1CdMQ2r24= Received: (qmail 75943 invoked by alias); 6 Feb 2017 21:12:02 -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 75922 invoked by uid 89); 6 Feb 2017 21:12:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=jasonredhatcom, U*jason, sk:jasonr, jason@redhat.com X-HELO: mail-ot0-f176.google.com Received: from mail-ot0-f176.google.com (HELO mail-ot0-f176.google.com) (74.125.82.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Feb 2017 21:11:59 +0000 Received: by mail-ot0-f176.google.com with SMTP id 32so71730937oth.3 for ; Mon, 06 Feb 2017 13:11:59 -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=dXAWsQPoQnWhi6v5VhEdjQxsW2/+dlA73aMQJuJjMdY=; b=CWv8+tkSBC0EvayuhHjaOlAnxRQSldk8aU7pN7kTSqywHMrcLFFisTNLSwTQjisTI6 EFg0yIeB7L3b2xsT9A61jWI3gwVyJdEBftx67JUsQ4804TTBkKmFsh/Y25EcRsp5OjCP zUp43bGTS91BOsvV0uHD299Q0ZljKNyl9MMlWLx6FdRU7mKKYEFnxotQXf+hwFM8047i avRdoYUaY6EeOEBax8Afh08zt5tQbeTguIp8D5fheYuCD3oUZSlXcFR8WdY8BYI695L6 wkflNOSqWJpK+qJBCtAPI1qTGeUgDwvJEt0k3cEQQBAMF7o+GrL0p+JcjxDw9JLtPr++ myFQ== X-Gm-Message-State: AMke39lJheq7iaYOxLrLrpaMsy6PF0kk482vhh4Yij4ZwPg8ZCcDJnpq+KwZNWuXCpvHzH9OBTA/YIPcMqcz5esb X-Received: by 10.157.52.66 with SMTP id v60mr5797715otb.61.1486415517483; Mon, 06 Feb 2017 13:11:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.173.104 with HTTP; Mon, 6 Feb 2017 13:11:36 -0800 (PST) From: Jason Merrill Date: Mon, 6 Feb 2017 16:11:36 -0500 Message-ID: Subject: C++ PATCH for c++/71193 (incomplete error in template) To: gcc-patches List X-IsSubscribed: yes 71193 is a case where we now properly treat as non-dependent some expressions that we previously considered type-dependent, and as a result try to resolve their containing expressions, which can lead to incomplete type errors that weren't seen before even though the code was ill-formed. This patch adjusts one situation this might occur to catch the problem, give a pedwarn instead of an error, and treat the expression as type-dependent. This doesn't help the testcase for 71773, where the access is more complicated. Tested x86_64-pc-linux-gnu, applying to trunk. commit debb4f99e55e5c0b8c64fd1957d41417dc951870 Author: Jason Merrill Date: Mon Feb 6 14:50:03 2017 -0500 PR c++/71193 - incomplete types in templates * parser.c (cp_parser_postfix_dot_deref_expression): In a template handle incomplete type by pedwarning and then treating as dependent. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0aa738b..1813adb 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7309,7 +7309,7 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser, /* Enter the scope corresponding to the type of the object given by the POSTFIX_EXPRESSION. */ - if (!dependent_p && TREE_TYPE (postfix_expression) != NULL_TREE) + if (!dependent_p) { scope = TREE_TYPE (postfix_expression); /* According to the standard, no expression should ever have @@ -7324,26 +7324,50 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser, required to be of complete type for purposes of class member access (5.2.5) outside the member function body. */ if (postfix_expression != current_class_ref + && scope != error_mark_node && !(processing_template_decl && current_class_type && (same_type_ignoring_top_level_qualifiers_p (scope, current_class_type)))) - scope = complete_type_or_else (scope, postfix_expression); - /* Let the name lookup machinery know that we are processing a - class member access expression. */ - parser->context->object_type = scope; - /* If something went wrong, we want to be able to discern that case, - as opposed to the case where there was no SCOPE due to the type - of expression being dependent. */ - if (!scope) - scope = error_mark_node; - /* If the SCOPE was erroneous, make the various semantic analysis - functions exit quickly -- and without issuing additional error - messages. */ - if (scope == error_mark_node) - postfix_expression = error_mark_node; + { + scope = complete_type (scope); + if (!COMPLETE_TYPE_P (scope)) + { + /* In a template, be permissive by treating an object expression + of incomplete type as dependent (after a pedwarn). */ + diagnostic_t kind = (processing_template_decl + ? DK_PEDWARN + : DK_ERROR); + cxx_incomplete_type_diagnostic + (location_of (postfix_expression), + postfix_expression, scope, kind); + if (processing_template_decl) + { + dependent_p = true; + scope = TREE_TYPE (postfix_expression) = NULL_TREE; + } + } + } + + if (!dependent_p) + { + /* Let the name lookup machinery know that we are processing a + class member access expression. */ + parser->context->object_type = scope; + /* If something went wrong, we want to be able to discern that case, + as opposed to the case where there was no SCOPE due to the type + of expression being dependent. */ + if (!scope) + scope = error_mark_node; + /* If the SCOPE was erroneous, make the various semantic analysis + functions exit quickly -- and without issuing additional error + messages. */ + if (scope == error_mark_node) + postfix_expression = error_mark_node; + } } - else + + if (dependent_p) /* Tell cp_parser_lookup_name that there was an object, even though it's type-dependent. */ parser->context->object_type = unknown_type_node; diff --git a/gcc/testsuite/g++.dg/template/incomplete8.C b/gcc/testsuite/g++.dg/template/incomplete8.C new file mode 100644 index 0000000..d6cde6a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/incomplete8.C @@ -0,0 +1,11 @@ +// PR c++/71193 +// { dg-options "" } + +class Heap; +class A { +public: + Heap *m_fn1(); +}; +template class B : A { + void m_fn2() { m_fn1()->HashSeed; } // { dg-warning "incomplete" } +};