Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-05-01 Thread Daniel Jacobowitz
On Thu, May 01, 2008 at 10:39:24AM -0500, Jason Kraftcheck wrote:
 Daniel Jacobowitz wrote:
 On Wed, Apr 30, 2008 at 05:51:32PM -0500, Jason Kraftcheck wrote:
 Why can't I take a reference to an rvalue?

 Because you can't modify rvalues.  This is the definition of the C++
 language.  The next major revision of C++ will have T rref, the two
 ampersands declaring an rvalue reference instead of the normal lvalue
 kind.

 Are you certain that the temporary created by invoking the copy  
 constructor is an rvalue?  If so, then why does the following syntax work?

 std::vectorint v;
 std::vectorint w( std:vectorint(v) );

 The copy constructor also takes a reference.  The only difference between 
 constructing 'w' and calling 'swap' on it is that the former takes a const 
 reference.

You are permitted to bind rvalues to const references, even when it
requires creation of a temporary.  This is 8.5.3 [dcl.init.ref] in the
C++ standard.

-- 
Daniel Jacobowitz
CodeSourcery



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-05-01 Thread Jason Kraftcheck
The same syntax is accepted by the only other C++ compiler I have access 
too: Sun's.  I guess what I don't understand is why, if I create a 
temporary by explicitly calling the copy constructor, that temporary is 
treated as an rvalue.


So how do you want to proceed?  If you're certain that you're correct 
then I have no objection to you closing the bug report. Please do so 
with my apologies for being a nuisance, as I'm certainly not sure that 
I'm correct.  Or if you prefer, I could post the question to comp.lang.c++.


thanks,

- jason



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-05-01 Thread Florian Weimer
* Jason Kraftcheck:

 The same syntax is accepted by the only other C++ compiler I have
 access too: Sun's.  I guess what I don't understand is why, if I
 create a temporary by explicitly calling the copy constructor, that
 temporary is treated as an rvalue.

The standard says so in section 3.10 (Lvalues and rvalues):

| 6 An expression which holds a temporary object resulting from a cast to
|   a nonreference type is an rvalue (this includes the explicit creation
|   of an object using functional notation (5.2.3)).

The type you're casting to is not a reference type, so it's an rvalue
according to section 5.4 (Explicit type conversion (cast notation)).



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-04-30 Thread Jason Kraftcheck
Package: g++-4.2
Version: 4.2.3-4
Severity: grave
Justification: renders package unusable


g++ refuses to compile the following syntax commonly used to force a 
std::vector to release allocated memory:

  #include vector
  int main()
  {
std::vectorint v;
v.clear();
v.swap( std::vectorint(v) );
return 0;
  }

I emmits the following  error message:

bug.cc: In function 'int main()':
bug.cc:6: error: no matching function for call to 'std::vectorint, 
  std::allocatorint ::swap(std::vectorint, std::allocatorint )'
/usr/include/c++/4.2/bits/stl_vector.h:728: note: candidates are: void 
  std::vector_Tp, _Alloc::swap(std::vector_Tp, _Alloc) [with _Tp = 
  int, _Alloc = std::allocatorint]



-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (990, 'stable'), (500, 'unstable'), (500, 'testing')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-6-amd64
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages g++-4.2 depends on:
ii  gcc-4.2   4.2.3-4The GNU C compiler
ii  gcc-4.2-base  4.2.3-4The GNU Compiler Collection (base 
ii  libc6 2.7-10 GNU C Library: Shared libraries
ii  libstdc++6-4.2-dev4.2.3-4The GNU Standard C++ Library v3 (d

g++-4.2 recommends no packages.

-- no debconf information



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Processed: Re: Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-04-30 Thread Debian Bug Tracking System
Processing commands for [EMAIL PROTECTED]:

 severity 478734 normal
Bug#478734: g++-4.2: refuses to compile valid C++ syntax
Severity set to `normal' from `grave'

 thanks
Stopping processing here.

Please contact me if you need assistance.

Debian bug tracking system administrator
(administrator, Debian Bugs database)


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-04-30 Thread Daniel Jacobowitz
severity 478734 normal
thanks

On Wed, Apr 30, 2008 at 11:55:19AM -0500, Jason Kraftcheck wrote:
 Severity: grave

This is not grave, g++ is perfectly usable for other code.

 I emmits the following  error message:
 
 bug.cc: In function 'int main()':
 bug.cc:6: error: no matching function for call to 'std::vectorint, 
   std::allocatorint ::swap(std::vectorint, std::allocatorint )'
 /usr/include/c++/4.2/bits/stl_vector.h:728: note: candidates are: void 
   std::vector_Tp, _Alloc::swap(std::vector_Tp, _Alloc) [with _Tp = 
   int, _Alloc = std::allocatorint]

I'm pretty sure GCC is correct to refuse this.  The result of a cast
is an rvalue, so you can not take a reference to it.

-- 
Daniel Jacobowitz
CodeSourcery



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-04-30 Thread Jason Kraftcheck

Daniel Jacobowitz wrote:

severity 478734 normal
thanks

On Wed, Apr 30, 2008 at 11:55:19AM -0500, Jason Kraftcheck wrote:

Severity: grave


This is not grave, g++ is perfectly usable for other code.


I emmits the following  error message:

bug.cc: In function 'int main()':
bug.cc:6: error: no matching function for call to 'std::vectorint, 
  std::allocatorint ::swap(std::vectorint, std::allocatorint )'
/usr/include/c++/4.2/bits/stl_vector.h:728: note: candidates are: void 
  std::vector_Tp, _Alloc::swap(std::vector_Tp, _Alloc) [with _Tp = 
  int, _Alloc = std::allocatorint]


I'm pretty sure GCC is correct to refuse this.  The result of a cast
is an rvalue, so you can not take a reference to it.



Why can't I take a reference to an rvalue?  The temporary is guaranteed 
to exist until the completion of the function it is passed to.  Further, 
the error message doesn't indicate that g++ interpreted the argument as 
const.




--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#478734: g++-4.2: refuses to compile valid C++ syntax

2008-04-30 Thread Daniel Jacobowitz
On Wed, Apr 30, 2008 at 05:51:32PM -0500, Jason Kraftcheck wrote:
 Why can't I take a reference to an rvalue?

Because you can't modify rvalues.  This is the definition of the C++
language.  The next major revision of C++ will have T rref, the two
ampersands declaring an rvalue reference instead of the normal lvalue
kind.

 the error message doesn't indicate that g++ interpreted the argument as  
 const.

Const is not the same as lvalue/rvalue.  It says you tried to pass a
std::vectorint where a std::vectorint  was required and the fact
that that was an error suggests that taking a reference is not
possible here.

-- 
Daniel Jacobowitz
CodeSourcery



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]