public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Gabriel Dos Reis <gdr@integrable-solutions.net>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: libstdc++/9679: Strange behaviour of valarray::apply method
Date: Wed, 12 Feb 2003 22:36:00 -0000	[thread overview]
Message-ID: <20030212223600.359.qmail@sources.redhat.com> (raw)

The following reply was made to PR libstdc++/9679; it has been noted by GNATS.

From: Gabriel Dos Reis <gdr@integrable-solutions.net>
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 <valarray>
 | #include <string.h>
 | 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<char> y(str, 6);
 | ///   Strange behaviour    
 |         char some = foo(&(y.apply(bar)[0]));
 |         return 0;
 | }
 | 
 | If I understood correctly then apply method should return valarray<char> 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<T> is permitted to return an
   object of another type, provided all the const member functions of
   valarray<T> 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<T>::operator[] const" returning a const T&; that, in effect,
 conflicts with loosened return type.  Too bad :-(
 
 -- Gaby


             reply	other threads:[~2003-02-12 22:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-12 22:36 Gabriel Dos Reis [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-02-12 22:16 dens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030212223600.359.qmail@sources.redhat.com \
    --to=gdr@integrable-solutions.net \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).