public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/39676]  New: std::result_of doesn't work
@ 2009-04-07 13:15 piotr dot wyderski at gmail dot com
  2009-04-07 13:19 ` [Bug libstdc++/39676] " paolo dot carlini at oracle dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: piotr dot wyderski at gmail dot com @ 2009-04-07 13:15 UTC (permalink / raw)
  To: gcc-bugs

------------------8<------------------

#include <functional>


int fn(long, float) {

    return 0;
}


int main(int argc, char *argv[]) {

    typedef std::result_of<decltype(fn)>::type type;
    return 0;
}

------------------8<------------------

$ g++ -std=c++0x testcase.cpp
In file included from
/opt/gcc-4.4.0-trunk/lib/gcc/i686-pc-cygwin/4.4.0/include/
c++/functional:75,
                 from testcase.cpp:2:
/opt/gcc-4.4.0-trunk/lib/gcc/i686-pc-cygwin/4.4.0/include/c++/tr1_impl/functiona
l: In instantiation of 'std::_Result_of_impl<false, int ()(long int, float)>':
/opt/gcc-4.4.0-trunk/lib/gcc/i686-pc-cygwin/4.4.0/include/c++/tr1_impl/functiona
l:154:   instantiated from 'std::result_of<int ()(long int, float)>'
testcase.cpp:13:   instantiated from here
/opt/gcc-4.4.0-trunk/lib/gcc/i686-pc-cygwin/4.4.0/include/c++/tr1_impl/functiona
l:200: error: 'int' is not a class, struct, or union type

gcc used is:

$ gcc -v
Using built-in specs.
Target: i686-pc-cygwin
Configured with: ../configure --prefix=/opt/gcc-4.4.0-trunk -v
--enable-bootstra
p --enable-version-specific-runtime-libs --enable-static --enable-shared
--enabl
e-shared-libgcc --with-gnu-ld --with-gnu-as --enable-sjlj-exceptions
--enable-la
nguages=c,c++ --disable-symvers --enable-libjava --disable-nls
--with-cpu-32=cor
e2 --with-cpu-64=core2 --enable-threads=posix
Thread model: posix
gcc version 4.4.0 20090309 (experimental) (GCC)


-- 
           Summary: std::result_of doesn't work
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: piotr dot wyderski at gmail dot com
  GCC host triplet: WinXP/x86/Cygwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
@ 2009-04-07 13:19 ` paolo dot carlini at oracle dot com
  2009-04-07 14:05 ` piotr dot wyderski at gmail dot com
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 13:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2009-04-07 13:19 -------
Note that *most* of the facilities in <functional> are still following the TR1
specifications, thus, in general, do not expect conformance to the latest C++0x
draft (or file a DR for each unimplemented behavior ;)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
  2009-04-07 13:19 ` [Bug libstdc++/39676] " paolo dot carlini at oracle dot com
@ 2009-04-07 14:05 ` piotr dot wyderski at gmail dot com
  2009-04-07 14:12 ` paolo dot carlini at oracle dot com
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: piotr dot wyderski at gmail dot com @ 2009-04-07 14:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from piotr dot wyderski at gmail dot com  2009-04-07 14:05 -------
(In reply to comment #1)
> Note that *most* of the facilities in <functional> are still following the TR1
> specifications, thus, in general, do not expect conformance to the latest C++0x
> draft (or file a DR for each unimplemented behavior ;)
>

The only C++0x functionality involved I am aware of is decltype,
which is outside of the template scope. BTW, 

boost::function_traits<...>::result_type

works flawlessly. Here is a simplified testcase:

#include <functional>

int main(int argc, char *argv[]) {

    typedef std::result_of<int (long, float)>::type type;
    return 0;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
  2009-04-07 13:19 ` [Bug libstdc++/39676] " paolo dot carlini at oracle dot com
  2009-04-07 14:05 ` piotr dot wyderski at gmail dot com
@ 2009-04-07 14:12 ` paolo dot carlini at oracle dot com
  2009-04-07 14:15 ` paolo dot carlini at oracle dot com
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 14:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2009-04-07 14:11 -------
Are you *really* sure the simplified testcase was supposed to work per the TR1
specifications? The author of thar code is Doug Gregor, and it never did in
GCC.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (2 preceding siblings ...)
  2009-04-07 14:12 ` paolo dot carlini at oracle dot com
@ 2009-04-07 14:15 ` paolo dot carlini at oracle dot com
  2009-04-07 14:32 ` piotr dot wyderski at gmail dot com
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 14:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo dot carlini at oracle dot com  2009-04-07 14:15 -------
I'm looking at 3.4/3 in n1836, and my answer is *no*.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (3 preceding siblings ...)
  2009-04-07 14:15 ` paolo dot carlini at oracle dot com
@ 2009-04-07 14:32 ` piotr dot wyderski at gmail dot com
  2009-04-07 14:35 ` paolo dot carlini at oracle dot com
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: piotr dot wyderski at gmail dot com @ 2009-04-07 14:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from piotr dot wyderski at gmail dot com  2009-04-07 14:31 -------
So it is a purely C++0x bug, as you indicated in your first reply.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (4 preceding siblings ...)
  2009-04-07 14:32 ` piotr dot wyderski at gmail dot com
@ 2009-04-07 14:35 ` paolo dot carlini at oracle dot com
  2009-04-07 14:46 ` jwakely dot gcc at gmail dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 14:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from paolo dot carlini at oracle dot com  2009-04-07 14:34 -------
Yes, a purely unimplemented C++0x feature.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (5 preceding siblings ...)
  2009-04-07 14:35 ` paolo dot carlini at oracle dot com
@ 2009-04-07 14:46 ` jwakely dot gcc at gmail dot com
  2009-04-07 14:47 ` paolo dot carlini at oracle dot com
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-04-07 14:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jwakely dot gcc at gmail dot com  2009-04-07 14:45 -------
I think you have the syntax wrong, if you want to know the return type of a
function type (or function pointer, or function reference) you need to say:

  result_of<int (*(long, float))(long ,float)>::type

what you probably want is:

  typedef int (*func_ptr)(long, float);
  result_of<func_ptr(long, float)>:type


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (6 preceding siblings ...)
  2009-04-07 14:46 ` jwakely dot gcc at gmail dot com
@ 2009-04-07 14:47 ` paolo dot carlini at oracle dot com
  2009-04-07 14:51 ` jwakely dot gcc at gmail dot com
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 14:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from paolo dot carlini at oracle dot com  2009-04-07 14:47 -------
Yes, that would work, we even have testcases for it. But what about C++0x,
Jonathan? Seems strange that only that more convoluted syntax is right...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (7 preceding siblings ...)
  2009-04-07 14:47 ` paolo dot carlini at oracle dot com
@ 2009-04-07 14:51 ` jwakely dot gcc at gmail dot com
  2009-04-07 14:57 ` paolo dot carlini at oracle dot com
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-04-07 14:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jwakely dot gcc at gmail dot com  2009-04-07 14:51 -------
This is not a bug in C++0x either.  The spec is:

Given an rvalue fn of type Fn and values t1, t2, ..., tN of types T1, T2, ...,
TN in ArgTypes, respectively,
the type member is the result type of the expression fn(t1, t2, ...,tN).

So the original testcase has Fn=int and tries to find the result of calling int
as a function, which is invalid.

The original testcase should be:

  typedef std::result_of<decltype(fn) (long, float)>::type type;

which tells you the result of invoking something of type decltype(fn) with
arguments of type long and float.

Or, to see what happens if you pass it other types:

  typedef std::result_of<decltype(fn) (int, double)>::type type;

This tells you the result of calling e.g. f(0, 0.0), which will result in the
arguments being implicitly converted, and as it's a simple function not a
function object or other callable type with multiple overloads, the result is
always 'int'

I believe this is not a bug.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (8 preceding siblings ...)
  2009-04-07 14:51 ` jwakely dot gcc at gmail dot com
@ 2009-04-07 14:57 ` paolo dot carlini at oracle dot com
  2009-04-07 15:02 ` piotr dot wyderski at gmail dot com
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 14:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from paolo dot carlini at oracle dot com  2009-04-07 14:56 -------
Gosh, thanks Jonathan for the explanation, the key word for me is
*overloading*, if overloading were not part of C++ these facilities would
probably be more "intuitive" to use. Agreed, let's give Piotr two minutes to
review your analysis and then let's close it.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (9 preceding siblings ...)
  2009-04-07 14:57 ` paolo dot carlini at oracle dot com
@ 2009-04-07 15:02 ` piotr dot wyderski at gmail dot com
  2009-04-07 15:41 ` jwakely dot gcc at gmail dot com
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: piotr dot wyderski at gmail dot com @ 2009-04-07 15:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from piotr dot wyderski at gmail dot com  2009-04-07 15:02 -------
Subject: Re:  std::result_of doesn't work

2009/4/7 jwakely dot gcc at gmail dot com <gcc-bugzilla@gcc.gnu.org>:

> what you probably want is:

In fact I want to copy the return type of a template method restore
and use as another method's return type ina C++0x way. This
works:

       class S {

        template <typename T>
          typename
boost::function_traits<decltype(traits<T>::restore)>::result_type

            restore() {

            return traits<T>::restore(*this);
        }
        };

but the std::result_of-based soludins do not. The lambda-like syntax
also does not work, because "this" is not available at the outer scope:

template <typename T> auto restore() -> decltype(traits<T>::restore(*this)) {

    return traits<T>::restore(*this);
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (10 preceding siblings ...)
  2009-04-07 15:02 ` piotr dot wyderski at gmail dot com
@ 2009-04-07 15:41 ` jwakely dot gcc at gmail dot com
  2009-04-07 15:42 ` jwakely dot gcc at gmail dot com
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-04-07 15:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from jwakely dot gcc at gmail dot com  2009-04-07 15:40 -------
See what I wrote at http://gcc.gnu.org/ml/libstdc++/2008-09/msg00124.html under
point 3)

You want this:

typename std::result_of< decltype(&traits<T>::restore) (S*) >::type

Paolo, let's close this.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (11 preceding siblings ...)
  2009-04-07 15:41 ` jwakely dot gcc at gmail dot com
@ 2009-04-07 15:42 ` jwakely dot gcc at gmail dot com
  2009-04-07 15:45 ` paolo dot carlini at oracle dot com
  2009-04-07 15:47 ` piotr dot wyderski at gmail dot com
  14 siblings, 0 replies; 16+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-04-07 15:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from jwakely dot gcc at gmail dot com  2009-04-07 15:42 -------
(In reply to comment #12)
> typename std::result_of< decltype(&traits<T>::restore) (S*) >::type

Oops, that should be S& not S*

It's not perfect, but for this case std::result_of works if you get the syntax
right :)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (12 preceding siblings ...)
  2009-04-07 15:42 ` jwakely dot gcc at gmail dot com
@ 2009-04-07 15:45 ` paolo dot carlini at oracle dot com
  2009-04-07 15:47 ` piotr dot wyderski at gmail dot com
  14 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-07 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #14 from paolo dot carlini at oracle dot com  2009-04-07 15:45 -------
Agreed ;)


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

* [Bug libstdc++/39676] std::result_of doesn't work
  2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
                   ` (13 preceding siblings ...)
  2009-04-07 15:45 ` paolo dot carlini at oracle dot com
@ 2009-04-07 15:47 ` piotr dot wyderski at gmail dot com
  14 siblings, 0 replies; 16+ messages in thread
From: piotr dot wyderski at gmail dot com @ 2009-04-07 15:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #15 from piotr dot wyderski at gmail dot com  2009-04-07 15:47 -------
Subject: Re:  std::result_of doesn't work

jwakely dot gcc at gmail dot com <gcc-bugzilla@gcc.gnu.org>:

> You want this:
>
> typename std::result_of< decltype(&traits<T>::restore) (S*) >::type

Thank you! :-)

> Paolo, let's close this.

Agreed. :-)

Best regards, Piotr


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39676


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

end of thread, other threads:[~2009-04-07 15:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-07 13:15 [Bug libstdc++/39676] New: std::result_of doesn't work piotr dot wyderski at gmail dot com
2009-04-07 13:19 ` [Bug libstdc++/39676] " paolo dot carlini at oracle dot com
2009-04-07 14:05 ` piotr dot wyderski at gmail dot com
2009-04-07 14:12 ` paolo dot carlini at oracle dot com
2009-04-07 14:15 ` paolo dot carlini at oracle dot com
2009-04-07 14:32 ` piotr dot wyderski at gmail dot com
2009-04-07 14:35 ` paolo dot carlini at oracle dot com
2009-04-07 14:46 ` jwakely dot gcc at gmail dot com
2009-04-07 14:47 ` paolo dot carlini at oracle dot com
2009-04-07 14:51 ` jwakely dot gcc at gmail dot com
2009-04-07 14:57 ` paolo dot carlini at oracle dot com
2009-04-07 15:02 ` piotr dot wyderski at gmail dot com
2009-04-07 15:41 ` jwakely dot gcc at gmail dot com
2009-04-07 15:42 ` jwakely dot gcc at gmail dot com
2009-04-07 15:45 ` paolo dot carlini at oracle dot com
2009-04-07 15:47 ` piotr dot wyderski at gmail dot com

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).