From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11872 invoked by alias); 13 May 2004 21:46:28 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 11825 invoked from network); 13 May 2004 21:46:20 -0000 Received: from unknown (HELO atom.nocdirect.com) (69.73.170.10) by sourceware.org with SMTP; 13 May 2004 21:46:20 -0000 Received: from [206.163.121.144] (helo=markab.pegasus.voria.net) by atom.nocdirect.com with esmtp (TLSv1:RC4-MD5:128) (Exim 4.34) id 1BOO1n-0006cd-QG; Thu, 13 May 2004 16:46:08 -0500 Subject: Re: Default argument for templatized function From: Adrian Bentley To: Jonathan Wakely Cc: gcc-help@gcc.gnu.org In-Reply-To: <20040513080515.GA63417@compsoc.man.ac.uk> References: <1084315475.4815.19.camel@localhost> <20040512083216.GB91267@compsoc.man.ac.uk> <1084384191.13011.0.camel@localhost> <20040513080515.GA63417@compsoc.man.ac.uk> Content-Type: text/plain Message-Id: <1084484773.4864.27.camel@localhost> Mime-Version: 1.0 Date: Thu, 13 May 2004 21:46:00 -0000 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - atom.nocdirect.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - voria.com X-Source: X-Source-Args: X-Source-Dir: X-SW-Source: 2004-05/txt/msg00170.txt.bz2 Yeah, ok, fine, it's nice to see that no one else finds this irritating. I fixed it already, but it is a hack (generics are supposed to be elegant...). However, gcc still seems to be inconsistent. The reason why the second one worked, was that I had two functions (one with a 3rd argument and one without). Shouldn't it cause a warning or something if it's ignoring a default argument like that, and there's a second function with the exact same first two? I mean sure it can all be chalked up to template weirdness, but sheesh. In the end these are all just work arounds for not being able to have default template arguments for functions (which should have been fixed long ago). Standards are good, but it seems to be becoming more and more inflexible, but perhaps that is just me being confused. Thanks for the smackdown folks (slightly enlightening though it was), I'll be sure to just fix what I've got in the future. Adruab On Thu, 2004-05-13 at 01:05, Jonathan Wakely wrote: > On Wed, May 12, 2004 at 10:49:51AM -0700, Adrian Bentley wrote: > > > Yeah, ok. I really do know what I'm talking about with C++, I just > > haven't > > been able to get it to do what I want :P. And I figured it was > > something > > like that (with respect to interpreting...), but why would it work so > > easily > > for the other case? (and yes just calling with the two parameters works > > just > > fine...) > > I can't get the code you posted (incomplete as it was) to compile with > GCC 2.95, 3.3, 3.4, or with Comeau's compiler. > > > I definitely know MANY ways to get around it, but it still makes generic > > programming WAY more of a pain in the ass if you can't let it figure > > things > > like that out for itself. > > The solution I posted does what you want, with little extra code. Making > it do it your way would require a change to the language, which is > unnecessary since you can achieve the desired effect as I showed. > > > Without the functionality of deriving the template for a default > > argument, > > which seems pretty straight forward to me by the way, it makes that a > > fairly > > gross limitation of gcc (lack of function specialization AND lack of > > ability > > to intuit from a default parameter). I know there could be some issues > > depending on the order the compiler goes through the steps, but man... > > it > > doesn't seem that complicated (I don't have any specific reference in > > Bjarne > > or anything...). > > You never said which version of the compiler you had tried, but it doesn't > matter as GCC is right to reject the code you posted. > > > So should I submit this as a bug then? It seems like the compiler > > should be > > able to do that (since it can't do def. template arguments for > > functions). > > That's the rules of the language. As llewelly said, see 14.8.2.4/17. > > Calling a function template with no arguments and without explicitly > stating which specialisation you want means that the compiler cannot > deduce the parameters. This is not a limitation of GCC. > > > Of course if they add default template arguments for functions... then > > it > > would be fine. Suggestions? > > You could submit a proposal for a language change to the standards > committee (but don't hold your breath for it to be accepted). > > jon