From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 374 invoked by alias); 12 Feb 2003 22:36:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 360 invoked by uid 71); 12 Feb 2003 22:36:00 -0000 Date: Wed, 12 Feb 2003 22:36:00 -0000 Message-ID: <20030212223600.359.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Gabriel Dos Reis Subject: Re: libstdc++/9679: Strange behaviour of valarray::apply method Reply-To: Gabriel Dos Reis X-SW-Source: 2003-02/txt/msg00543.txt.bz2 List-Id: The following reply was made to PR libstdc++/9679; it has been noted by GNATS. From: Gabriel Dos Reis To: dens@stl.sarov.ru Cc: gcc-gnats@gcc.gnu.org Subject: Re: libstdc++/9679: Strange behaviour of valarray::apply method Date: 12 Feb 2003 23:33:04 +0100 dens@stl.sarov.ru writes: | >Number: 9679 | >Category: libstdc++ | >Synopsis: Strange behaviour of valarray::apply method strange but standard conforming with C++98, not C++0x... [...] | #include | #include | char bar(char arg) | { | return tolower(arg); | } | | char foo(char * x) | { | return toupper(*x); | } | | int main(void) | { | char * str = new char[7]; | strcpy(str,"STRING"); | | std::valarray y(str, 6); | /// Strange behaviour | char some = foo(&(y.apply(bar)[0])); | return 0; | } | | If I understood correctly then apply method should return valarray object which operator [] should return reference to char (char &). (C++ standard 26.3.2.3 and 26.3.2.7 8.) | | But in our case this operator returns non-lvalue and I can't get it address. It is very strange for me. Here is what is happening. Firstly, let's recall 26.3.1/3: Any function returning a valarray is permitted to return an object of another type, provided all the const member functions of valarray are also applicable to this type. This return type shall not add more than two levels of template nesting over the most deeply nested argument type. apply() being a const member function actually returns something that is -not- a valarray. Subsequent application of operator[] to that object is considered to be application of "operator[] const" which is defined by C++08 to return an rvalue. Therefore, pedantically speaking your program is not required to compile. However, I happen to be the other guy that champions "valarray::operator[] const" returning a const T&; that, in effect, conflicts with loosened return type. Too bad :-( -- Gaby