public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54111] New: function return type template deduction
@ 2012-07-28  7:46 leonid at volnitsky dot com
  2012-08-02  4:02 ` [Bug c++/54111] " leonid at volnitsky dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: leonid at volnitsky dot com @ 2012-07-28  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54111
           Summary: function return type template deduction
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: leonid@volnitsky.com


Created attachment 27882
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27882
4 source code files.

Possible regression. 

There are 4 version of slightly different versions of below code (file
bug-u2.cc): 

-----------------------------------------------------
    #include <tuple>

    template<typename T, typename U> 
    U operator* (T x,  U& (*f)(T&) ) {  
        return (*f)(x);
    }; 

    int main() {
        std::tuple<int,int>  tpl(42,43);
        return   tpl * std::get<0,int,int>;
    }  
----------------------------------------------------

These 4 versions are combination of 2 variants:
- if template parameter U  or hardcoded type int is used (codes int or u) 
- if get<0,int,int>  or get<0> is used (codes 2 and 0)

4 version of above code are attached. 

For 3 versions of GCC that I have:

               453     471     480-pre 
--------------------------------------
bug-int0.cc    accp    accp    accp    
bug-int2.cc    accp    rej     rej     
bug-u0.cc      rej     rej     rej     
bug-u2.cc      accp    rej     rej   

It seems that gcc463 behave the same as 453.


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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
@ 2012-08-02  4:02 ` leonid at volnitsky dot com
  2012-08-02 10:18 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: leonid at volnitsky dot com @ 2012-08-02  4:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-08-02 04:02:27 UTC ---
I've just tested with gcc-463.    It accept/reject exactly the same as gcc-453.


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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
  2012-08-02  4:02 ` [Bug c++/54111] " leonid at volnitsky dot com
@ 2012-08-02 10:18 ` redi at gcc dot gnu.org
  2012-08-02 11:13 ` leonid at volnitsky dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-08-02 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-02 10:18:44 UTC ---
FWIW Clang 3.2 accepts bug-int?.cc and rejects bug-u?.cc


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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
  2012-08-02  4:02 ` [Bug c++/54111] " leonid at volnitsky dot com
  2012-08-02 10:18 ` redi at gcc dot gnu.org
@ 2012-08-02 11:13 ` leonid at volnitsky dot com
  2012-08-02 13:13 ` leonid at volnitsky dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: leonid at volnitsky dot com @ 2012-08-02 11:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-08-02 11:13:26 UTC ---
if in bug-int2.cc (and only in this file) to replace tuple with pair - it
becomes accepted by any gcc version.


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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
                   ` (2 preceding siblings ...)
  2012-08-02 11:13 ` leonid at volnitsky dot com
@ 2012-08-02 13:13 ` leonid at volnitsky dot com
  2012-08-15 17:35 ` leonid at volnitsky dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: leonid at volnitsky dot com @ 2012-08-02 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-08-02 13:12:44 UTC ---
Please disregard my last message (about std::pair) - it was incorrect.


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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
                   ` (3 preceding siblings ...)
  2012-08-02 13:13 ` leonid at volnitsky dot com
@ 2012-08-15 17:35 ` leonid at volnitsky dot com
  2020-12-08  7:47 ` tom at geus dot me
  2020-12-08 10:32 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: leonid at volnitsky dot com @ 2012-08-15 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-08-15 17:34:41 UTC ---
More combinatorics and more test (gcc-trunk, clang-trunk and gcc463).  Now
everything in one file. 
-----------------------------------------------------------------

#include <tuple>
#include <utility>
using namespace std;


      int&  plaint_f(      int& x) {return x;};
const int&  plaint_f(const int& x) {return x;};

template<class T, class R>
R eval (T& x,  R& (*f)(T&)) { 
    return (*f)(x);
};

template<class T, class R>
R eval_const (const T& x,  const R& (*f)(const T&)) { 
    return (*f)(x);
};


template<class T, class R=int>
R eval_tuple_int (T& x,  R& (*f)(T&)) { 
    return (*f)(x);
};

template<class T, class R=int>
R eval_tuple_int_const (T& x,  const R& (*f)(const T&)) { 
    return (*f)(x);
};


template<class ...Ts, class R>
R eval_tuple (tuple<Ts...>& x,  R& (*f)(tuple<Ts...>&)) { 
    return (*f)(x);
};

template<class ...Ts, class R=int>
R eval_tuple_int (tuple<Ts...>& x,  R& (*f)(tuple<Ts...>&)) { 
    return (*f)(x);
};

template<class ...Ts, class R>
R eval_tuple_const (const tuple<Ts...>& x,  R& (*f)(const tuple<Ts...>&)) { 
    return (*f)(x);
};

template<class ...Ts, class R=int>
R eval_tuple_const_int (const tuple<Ts...>& x,  R& (*f)(const tuple<Ts...>&)) { 
    return (*f)(x);
};


int main() {

    //  int i42=42;
    //  return  eval(i42, plaint_f);
    //  OK

                        // 20.4.2.6  GET<..>(TUPLE) 
                        //  
                        //  template <size_t I, class... Types>
                        //  typename tuple_element<I, tuple<Types...> >::type&
get(tuple<Types...>&) noexcept;
                        //  
                        //  template <size_t I, class... types>
                        //  typename tuple_element<I, tuple<Types...> >::type&&
get(tuple<Types...>&&) noexcept;
                        //  
                        //  template <size_t I, class... types>
                        //  typename tuple_element<I, tuple<Types...> >::type
const& get(const tuple<Types...>&) noexcept;


    tuple<int,int>  tpl(42,43);

    //////  INT eval..(TUPLE)

    //  return  eval_tuple_int(tpl, get<0,int,int>);
    //    gcc48-ERROR   types ‘tuple<_Elements ...>’ and ‘const pair<int, int>’
have incompatible cv-qualifiers
    //    gcc46-OK
    //    clang-OK

    //  return  eval_tuple_int(tpl, get<0>);
    //    gcc48-OK
    //    gcc46-OK
    //    clang-OK 

    //  return  eval_tuple_int_const(tpl, get<0,int,int>);
    //    gcc48-OK
    //    gcc46-OK
    //    clang-OK

    //  return  eval_tuple_int_const(tpl, get<0>);
    //    gcc48-OK
    //    gcc46-OK
    //    clang-OK


    //////  eval(TUPLE)

    //  return  eval(tpl, get<0>);
    //    gcc48-ERROR   couldn't deduce template parameter ‘R’
    //    gcc46-ERROR
    //    clang-ERROR   couldn't infer template argument 'R'

    //  return  eval(tpl, get<0,int,int>);
    //    gcc48-ERROR   could not resolve address from overloaded function
‘get<0, int, int>’   
    //    gcc46-OK
    //    clang-ERROR   couldn't infer template argument 'R'

    //  return  eval_const(tpl, get<0>);
    //    gcc48-ERROR   couldn't deduce template parameter ‘R’
    //    gcc46-ERROR
    //    clang-ERROR   couldn't infer template argument 'R'

    //  return  eval_const(tpl, get<0,int,int>);
    //    gcc48-OK
    //    gcc46-OK
    //    clang-ERROR   couldn't infer template argument 'R'

    //////  eval_tuple..(TUPLE)

    //  return  eval_tuple(tpl, get<0,int,int>);
    //    gcc48-ERROR   types ‘tuple<_Elements ...>’ and ‘const tuple<int,
int>’ have incompatible cv-qualifiers
    //    gcc46-OK
    //    clang-OK

    //  return  eval_tuple_const(tpl, get<0,int,int>);
    //    gcc48-OK
    //    gcc46-OK
    //    clang-OK

    //  return  eval_tuple_const(tpl, get<0>);   
    //    gcc48-ERROR   couldn't deduce template parameter ‘R’
    //    gcc46-ERROR
    //    clang-ERROR

}


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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
                   ` (4 preceding siblings ...)
  2012-08-15 17:35 ` leonid at volnitsky dot com
@ 2020-12-08  7:47 ` tom at geus dot me
  2020-12-08 10:32 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: tom at geus dot me @ 2020-12-08  7:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54111

Tom de Geus <tom at geus dot me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tom at geus dot me

--- Comment #6 from Tom de Geus <tom at geus dot me> ---
I can confirm that this bug is still there, e.g. on the standard gcc on the
latest Ubuntu. Clang and MSVS are compiling fine. 

Here is my failing (similar) problem:

```cpp
#include <iostream>
#include <vector>

template <class T>
auto foo(const T* A)
{
    return A[0];
}

template <class T>
struct impl
{
    template <typename F>
    static auto bar(const T& A, F func)
    {
        return func(&A[0]);
    }
};

int main()
{
    std::vector<size_t> A = {20, 3, 4};

    std::cout << impl<decltype(A)>::bar(A, &foo<size_t>) << std::endl;

    return 0;
}
```

See
https://stackoverflow.com/questions/65183976/infer-template-argument-for-pointer-to-function/65186031#65186031

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

* [Bug c++/54111] function return type template deduction
  2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
                   ` (5 preceding siblings ...)
  2020-12-08  7:47 ` tom at geus dot me
@ 2020-12-08 10:32 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-08 10:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54111

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's actually fixed in trunk.

*** This bug has been marked as a duplicate of bug 64194 ***

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

end of thread, other threads:[~2020-12-08 10:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-28  7:46 [Bug c++/54111] New: function return type template deduction leonid at volnitsky dot com
2012-08-02  4:02 ` [Bug c++/54111] " leonid at volnitsky dot com
2012-08-02 10:18 ` redi at gcc dot gnu.org
2012-08-02 11:13 ` leonid at volnitsky dot com
2012-08-02 13:13 ` leonid at volnitsky dot com
2012-08-15 17:35 ` leonid at volnitsky dot com
2020-12-08  7:47 ` tom at geus dot me
2020-12-08 10:32 ` redi at gcc dot gnu.org

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