From patchwork Fri May 10 14:29:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 242997 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id D04212C00B2 for ; Sat, 11 May 2013 00:30:03 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=wLWM2+M7VHASpiS9hidiISWKczhuWyZti60zvbG+ml/d+2 OtU4u9c2h+vfsWwYc/gAFrkhQITd7RPHAGNu04GkfQ/V9G2mI7UlwSwnEY2EU/MC rEjC9Xn8PRcjxKpMltbapxmwYr5Ucx5yPWWgAdnU/3+8KfegiAMTV/FYoi1Ek= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=uK0jRbcoLS3GKhkXK3oGajqz4v0=; b=kYFonjn5M3XrDQKdkNJX ZjqdPGMeZ2DWGvH/4ibhf3iychqr1pafFbmZ35wuK6hU9WYQQW1vynK6MSExYmJQ Pm45Y5Fa8Ktbm5/Be55XEV3EOfdm1pOpg1F7kDwVwuoAAeVeWz7AjT3C9zQoMEMw 5r6kiMDsZZRS6uX5R0q1ojI= Received: (qmail 24226 invoked by alias); 10 May 2013 14:29:30 -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 24196 invoked by uid 89); 10 May 2013 14:29:30 -0000 X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS, TW_SV autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 10 May 2013 14:29:29 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4AETSSW010517 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 10 May 2013 10:29:28 -0400 Received: from [10.3.113.45] (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4AETRBj003541 for ; Fri, 10 May 2013 10:29:28 -0400 Message-ID: <518D0447.4010002@redhat.com> Date: Fri, 10 May 2013 10:29:27 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/57196 (wrong error with initializer-list constructor) X-Virus-Found: No When I added the check for instantiation-dependent expressions, I treated statement-expressions and some qualified-ids as instantiation-dependent even when they don't involve template parameters. In this PR, that causes problems because array initialization expands into a statement-expression via build_vec_init, and a sizeof-expression is not immediately folded, and then when we go to convert the sizeof to the appropriate type for the template non-type parameter, we call uses_template_parms, which pretends we're in a template, we look inside the sizeof and see the statement-expression, and decide that it's dependent. The solution is not to pretend that we're in a template when deciding whether a template argument is dependent. Tested x86_64-pc-linux-gnu, applying to trunk. If no problems turn up, I'll apply it to 4.8 later as well. commit 32bf8cd06a9d5e2ad4abd35ce3571457a071b27d Author: jason Date: Fri May 10 14:17:45 2013 +0000 PR c++/57196 * pt.c (convert_template_argument): Use dependent_template_arg_p, not uses_template_parms. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198778 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0747de6..8f88b10 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6368,7 +6368,8 @@ convert_template_argument (tree parm, val = error_mark_node; } } - else if (!uses_template_parms (orig_arg) && !uses_template_parms (t)) + else if (!dependent_template_arg_p (orig_arg) + && !uses_template_parms (t)) /* We used to call digest_init here. However, digest_init will report errors, which we don't want when complain is zero. More importantly, digest_init will try too diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist70.C b/gcc/testsuite/g++.dg/cpp0x/initlist70.C new file mode 100644 index 0000000..f215b9d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist70.C @@ -0,0 +1,27 @@ +// PR c++/57196 +// { dg-require-effective-target c++11 } + +#include + +template +struct set { + set() = default; + set(std::initializer_list){} +}; + +struct string { + string(const char*){} + ~string(){} +}; + +typedef decltype(sizeof(0)) size_t; + +template struct EqHelper { }; + +int IsNullLiteralHelper(...); + +void Fn() { + EqHelper{1})> eq1; // ok + EqHelper())> eq2; // ok + EqHelper{"foo"})> eq3; // error +} diff --git a/gcc/testsuite/g++.dg/template/crash106.C b/gcc/testsuite/g++.dg/template/crash106.C index c2d117e..ebd47bc 100644 --- a/gcc/testsuite/g++.dg/template/crash106.C +++ b/gcc/testsuite/g++.dg/template/crash106.C @@ -10,3 +10,5 @@ struct A template > struct B {}; // { dg-error "type|declared" } B<> b; // { dg-error "type|declaration" } + +// { dg-prune-output "could not convert" } diff --git a/gcc/testsuite/g++.dg/template/crash112.C b/gcc/testsuite/g++.dg/template/crash112.C index 919c887..ff35764 100644 --- a/gcc/testsuite/g++.dg/template/crash112.C +++ b/gcc/testsuite/g++.dg/template/crash112.C @@ -5,7 +5,7 @@ struct A template void foo() {} }; -template struct B {}; // { dg-error "declaration" } +template struct B {}; template struct C { @@ -13,3 +13,5 @@ template struct C }; C<0> c; + +// { dg-prune-output "could not convert" } diff --git a/gcc/testsuite/g++.dg/template/dependent-args1.C b/gcc/testsuite/g++.dg/template/dependent-args1.C index 0b197cf..a540e55 100644 --- a/gcc/testsuite/g++.dg/template/dependent-args1.C +++ b/gcc/testsuite/g++.dg/template/dependent-args1.C @@ -9,3 +9,5 @@ struct A template > struct B {}; B b; // { dg-error "type/value mismatch|expected a constant|invalid type" } + +// { dg-prune-output "could not convert" }