From patchwork Tue Oct 26 18:02:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 69280 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]) by ozlabs.org (Postfix) with SMTP id C3C97B6EF0 for ; Wed, 27 Oct 2010 05:02:36 +1100 (EST) Received: (qmail 25622 invoked by alias); 26 Oct 2010 18:02:32 -0000 Received: (qmail 25601 invoked by uid 22791); 26 Oct 2010 18:02:30 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Oct 2010 18:02:25 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9QI2Oig007999 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Oct 2010 14:02:24 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9QI2Nda018459 for ; Tue, 26 Oct 2010 14:02:23 -0400 Message-ID: <4CC717AF.1030509@redhat.com> Date: Tue, 26 Oct 2010 14:02:23 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.14) Gecko/20101020 Lightning/1.0b1 Shredder/3.0.10pre MIME-Version: 1.0 To: gcc-patches List Subject: Small C++ PATCH to add context to error messages about invalid template arguments 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 While looking at another issue, I was confused by messages talking about one template instantiation as context for an error about an invalid template argument which was actually an argument for a different template in the definition of the instantiation described in the error message. This patch causes us to push a template instantiation context level before converting template arguments so that the printed context includes the template we're trying to provide arguments for. Tested x86_64-pc-linux-gnu, applied to trunk. commit 07d43402f88ca5c539d670657cbe0b7b18b43f36 Author: Jason Merrill Date: Tue Oct 26 00:47:47 2010 -0400 * pt.c (lookup_template_class): push_tinst_level around call to coerce_template_parms. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 88ebd47..f1a9d17 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6600,13 +6600,17 @@ lookup_template_class (tree d1, arglist = bound_args; } else - arglist - = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parmlist), - INNERMOST_TEMPLATE_ARGS (arglist), - gen_tmpl, - complain, - /*require_all_args=*/true, - /*use_default_args=*/true); + { + push_tinst_level (templ); + arglist + = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parmlist), + INNERMOST_TEMPLATE_ARGS (arglist), + gen_tmpl, + complain, + /*require_all_args=*/true, + /*use_default_args=*/true); + pop_tinst_level (); + } if (arglist == error_mark_node) /* We were unable to bind the arguments. */ diff --git a/gcc/testsuite/g++.dg/template/arg8.C b/gcc/testsuite/g++.dg/template/arg8.C new file mode 100644 index 0000000..5b3a31c --- /dev/null +++ b/gcc/testsuite/g++.dg/template/arg8.C @@ -0,0 +1,12 @@ +// Test for a message indicating what template we're trying to convert +// arguments for. We can't actually test for it directly because it +// doesn't have an associated line number, but we can test for the +// "instantiated from here" message that follows. + +template +struct A { }; + +int i; +A a; // { dg-message "instantiated from here" } +// { dg-error "not a valid template argument" "" { target *-*-* } 10 } +// { dg-error "invalid type in declaration" "" { target *-*-* } 10 }