This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/9679: Strange behaviour of valarray::apply method


>Number:         9679
>Category:       libstdc++
>Synopsis:       Strange behaviour of valarray::apply method
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 12 22:16:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     dens@stl.sarov.ru
>Release:        libstdc++-3.2-7
>Organization:
>Environment:
cat /etc/issue
Red Hat Linux release 8.0 (Psyche)
Kernel \r on an \m

g++ --version
g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
>Description:
There is very strange(for me) behaviour of apply method of valarray:

#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.
>How-To-Repeat:
Try to compile attached sample
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="new.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="new.cpp"

I2luY2x1ZGUgPHZhbGFycmF5PgojaW5jbHVkZSA8c3RyaW5nLmg+CmNoYXIgYmFyKGNoYXIgYXJn
KQp7CiAgICByZXR1cm4gdG9sb3dlcihhcmcpOwp9CgpjaGFyIGZvbyhjaGFyICogeCkKewogICAg
cmV0dXJuIHRvdXBwZXIoKngpOwp9CgppbnQgbWFpbih2b2lkKQp7CgljaGFyICogc3RyID0gbmV3
IGNoYXJbN107CglzdHJjcHkoc3RyLCJTVFJJTkciKTsKCglzdGQ6OnZhbGFycmF5PGNoYXI+IHko
c3RyLCA2KTsKCWNoYXIgc29tZSA9IGZvbygmKHkuYXBwbHkoYmFyKVswXSkpOwoJcmV0dXJuIDA7
Cn0K


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]