public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Const in default function arguments?
@ 2003-04-05 11:30 Eric Lemings
  2003-04-05 12:24 ` Nathan Sidwell
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Lemings @ 2003-04-05 11:30 UTC (permalink / raw)
  To: eljay, nathan; +Cc: gcc-help

That's a bit different.  The type of the default argument here
is T&.  In the original post, the type is T.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
  2003-04-05 11:30 Const in default function arguments? Eric Lemings
@ 2003-04-05 12:24 ` Nathan Sidwell
  0 siblings, 0 replies; 9+ messages in thread
From: Nathan Sidwell @ 2003-04-05 12:24 UTC (permalink / raw)
  To: Eric Lemings; +Cc: eljay, gcc-help

Eric Lemings wrote:
> That's a bit different.  The type of the default argument here
> is T&.  In the original post, the type is T.
ok,
	class T {...};
	void Baz (T = T ());
what's the problem? AFAICT, someone was making the blanket statement
that 'thou shall not have default values for non-constant argument
types'. such a statement is false.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
  2003-04-04 18:10 Eric Lemings
  2003-04-04 19:59 ` John Love-Jensen
@ 2003-04-05 16:24 ` LLeweLLyn Reese
  1 sibling, 0 replies; 9+ messages in thread
From: LLeweLLyn Reese @ 2003-04-05 16:24 UTC (permalink / raw)
  To: Eric Lemings; +Cc: eljay, eric, gcc-help

Eric Lemings <elemings@lemings.com> writes:

> void foo (int i) {
>   ++i;
> }
> 
> This function foo doesn't make sense either but it's not a
> compile error.  Just because something doesn't make sense
> doesn't mean it's illegal.  Sounds like the non-const
> parameter should be a warning, not an error.

No. non-const parameters should cause no warnings, and cause no errors
    (as they do now)

Your original post made the error of binding a temporary to a
    reference to non-const. That is quite independent of const
    parameters or default parameters.

Binding a temporary to a reference to non-const is ill-formed. Some
    feel that language rule ought to be changed, but that is a
    discussion for another forum (e.g. comp.lang.c++.moderated)

[snip]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
  2003-04-04 19:59 ` John Love-Jensen
@ 2003-04-05 10:27   ` Nathan Sidwell
  0 siblings, 0 replies; 9+ messages in thread
From: Nathan Sidwell @ 2003-04-05 10:27 UTC (permalink / raw)
  To: John Love-Jensen; +Cc: Eric Lemings, eric, gcc-help

John Love-Jensen wrote:
> Hi Eric,
> 
> 
>>Can somebody not point to the standard that says you can't use a default
> 
> function argument for a non-const parameter?
but of course you can.

	int &Foo ();
	void Baz (int & = Foo ());

is just fine.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
@ 2003-04-04 20:12 Eric Lemings
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Lemings @ 2003-04-04 20:12 UTC (permalink / raw)
  To: elemings, eljay, eric, gcc-help

That's good enough for me.  Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
  2003-04-04 18:10 Eric Lemings
@ 2003-04-04 19:59 ` John Love-Jensen
  2003-04-05 10:27   ` Nathan Sidwell
  2003-04-05 16:24 ` LLeweLLyn Reese
  1 sibling, 1 reply; 9+ messages in thread
From: John Love-Jensen @ 2003-04-04 19:59 UTC (permalink / raw)
  To: Eric Lemings, eric, gcc-help

Hi Eric,

> Can somebody not point to the standard that says you can't use a default
function argument for a non-const parameter?

I don't have the standard (ISO 14882) on hand.

However, if you have some confidence in Stroustrup's C++PL (3rd ed), you can
read 10.4.10 and 5.5 which states that doing so is illegal.

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
@ 2003-04-04 18:10 Eric Lemings
  2003-04-04 19:59 ` John Love-Jensen
  2003-04-05 16:24 ` LLeweLLyn Reese
  0 siblings, 2 replies; 9+ messages in thread
From: Eric Lemings @ 2003-04-04 18:10 UTC (permalink / raw)
  To: eljay, eric, gcc-help

void foo (int i) {
  ++i;
}

This function foo doesn't make sense either but it's not a
compile error.  Just because something doesn't make sense
doesn't mean it's illegal.  Sounds like the non-const
parameter should be a warning, not an error.

An error means that it's illegal and the standard defines
what is legal and what is not.  Can somebody not point to
the standard that says you can't use a default function
argument for a non-const parameter?

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Const in default function arguments?
  2003-04-03 22:10 Eric Lemings
@ 2003-04-04 12:32 ` John Love-Jensen
  0 siblings, 0 replies; 9+ messages in thread
From: John Love-Jensen @ 2003-04-04 12:32 UTC (permalink / raw)
  To: Eric Lemings, gcc-help

Hi Eric,

>Why won't the non-const version compile?

Because by making it a non-const reference, you are saying that you are
going to modify it.  That is to say, you are making an "OUT" or "UPDATE"
(in/out) parameter.

When you specify a default object, you are making a temporary.

It doesn't make sense to modify a temporary.

--Eljay

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Const in default function arguments?
@ 2003-04-03 22:10 Eric Lemings
  2003-04-04 12:32 ` John Love-Jensen
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Lemings @ 2003-04-03 22:10 UTC (permalink / raw)
  To: gcc-help

[elemings@cyberia c++]$ g++ --version
g++ (GCC) 3.2.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[elemings@cyberia c++]$ more Test01.cpp

#include <iostream>

struct Foo {
  int i;
};

struct Bar: public Foo {
  // empty class body
};

void G (const Foo& f = Bar ()) {
  std::cout << f.i << std::endl;
}

[elemings@cyberia c++]$ diff Test01.cpp Test02.cpp
12c12
< void G (const Foo& f = Bar ()) {
---
> void G (Foo& f = Bar ()) {
[elemings@cyberia c++]$ g++ -g -Wall -pedantic -c Test01.cpp
[elemings@cyberia c++]$ g++ -g -Wall -pedantic -c Test02.cpp
Test02.cpp:12: default argument for `Foo&f' has type `Bar'

Why won't the non-const version compile?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-04-05 16:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-05 11:30 Const in default function arguments? Eric Lemings
2003-04-05 12:24 ` Nathan Sidwell
  -- strict thread matches above, loose matches on Subject: below --
2003-04-04 20:12 Eric Lemings
2003-04-04 18:10 Eric Lemings
2003-04-04 19:59 ` John Love-Jensen
2003-04-05 10:27   ` Nathan Sidwell
2003-04-05 16:24 ` LLeweLLyn Reese
2003-04-03 22:10 Eric Lemings
2003-04-04 12:32 ` John Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).