public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63515] New: unused templated member can be instatiated
@ 2014-10-12 18:47 luka.rahne at gmail dot com
  2014-10-13 22:01 ` [Bug c++/63515] " luka.rahne at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: luka.rahne at gmail dot com @ 2014-10-12 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63515
           Summary: unused templated member can be instatiated
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luka.rahne at gmail dot com

Created attachment 33694
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33694&action=edit
source that fails

I was working on curried functions and came across some unusual behaviour.
(compilation fails with error)

I have trimmed some code and put relevant comments in source.

compiler: g++ 5.0 -> commit 9bf79212ecec2245e66156c2b18d8a76a0187b04
flags:  -O3  -Wall -Wextra -std=c++11


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

* [Bug c++/63515] unused templated member can be instatiated
  2014-10-12 18:47 [Bug c++/63515] New: unused templated member can be instatiated luka.rahne at gmail dot com
@ 2014-10-13 22:01 ` luka.rahne at gmail dot com
  2014-10-13 22:03 ` luka.rahne at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: luka.rahne at gmail dot com @ 2014-10-13 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Luka Rahne <luka.rahne at gmail dot com> ---
Created attachment 33704
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33704&action=edit
Shorter Example


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

* [Bug c++/63515] unused templated member can be instatiated
  2014-10-12 18:47 [Bug c++/63515] New: unused templated member can be instatiated luka.rahne at gmail dot com
  2014-10-13 22:01 ` [Bug c++/63515] " luka.rahne at gmail dot com
@ 2014-10-13 22:03 ` luka.rahne at gmail dot com
  2014-10-13 22:54 ` [Bug c++/63515] Deduced number of parameters can be deduced from unrelated type luka.rahne at gmail dot com
  2021-08-10  0:31 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: luka.rahne at gmail dot com @ 2014-10-13 22:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Luka Rahne <luka.rahne at gmail dot com> ---
This bug boils to to point where in member function

    template <typename... Rem>
    CurriedImpl<Depth-sizeof...(Rem),F> 
    //sizeof...(Rem) depends here on size of arguments of std::function
    operator()(Rem ... a_rem) 
    {
    }

deduced number of arguments depends on number of arguments in F


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

* [Bug c++/63515] Deduced number of parameters can be deduced from unrelated type
  2014-10-12 18:47 [Bug c++/63515] New: unused templated member can be instatiated luka.rahne at gmail dot com
  2014-10-13 22:01 ` [Bug c++/63515] " luka.rahne at gmail dot com
  2014-10-13 22:03 ` luka.rahne at gmail dot com
@ 2014-10-13 22:54 ` luka.rahne at gmail dot com
  2021-08-10  0:31 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: luka.rahne at gmail dot com @ 2014-10-13 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Luka Rahne <luka.rahne at gmail dot com> ---
Extra observations:

It looks to me that assignment "auto c = CurriedImpl<2,some_type>(f);" tries to
construct an operator();

If operator() is renamed to function fun or assignment is replaced by
constructor there is no issues.


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

* [Bug c++/63515] Deduced number of parameters can be deduced from unrelated type
  2014-10-12 18:47 [Bug c++/63515] New: unused templated member can be instatiated luka.rahne at gmail dot com
                   ` (2 preceding siblings ...)
  2014-10-13 22:54 ` [Bug c++/63515] Deduced number of parameters can be deduced from unrelated type luka.rahne at gmail dot com
@ 2021-08-10  0:31 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-10  0:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The shorter example works in C++17 mode in GCC 7+.  It is still rejected in
C++11 and C++14 (hitting the assert).
clang accepts the shorter example in all modes.
ICC rejects it with the assert in all modes.
MSVC accepts it in at least C++latest mode (I did not try others).



The original example fails in C++17 mode still (and gives the same error
message as C++14 mode):
<source>: In instantiation of 'struct CurriedImpl<-894, std::function<int(int,
int)>, int, int>':
<source>:16:8:   recursively required from 'struct CurriedImpl<-2,
std::function<int(int, int)>, int, int>'
<source>:16:8:   required from 'struct CurriedImpl<-1, std::function<int(int,
int)>, int, int>'
/opt/compiler-explorer/gcc-trunk-20210809/include/c++/12.0.0/type_traits:2924:69:
  required by substitution of 'template<class _Tp, class> static std::true_type
std::__is_invocable_impl<std::__invoke_result<CurriedImpl<1,
std::function<int(int, int)>, int, int>&, int, int>, int, false,
void>::_S_test(int) [with _Tp = int; <template-parameter-1-2> = <missing>]'
/opt/compiler-explorer/gcc-trunk-20210809/include/c++/12.0.0/type_traits:2933:42:
  required from 'struct
std::__is_invocable_impl<std::__invoke_result<CurriedImpl<1,
std::function<int(int, int)>, int, int>&, int, int>, int, false, void>'
/opt/compiler-explorer/gcc-trunk-20210809/include/c++/12.0.0/bits/std_function.h:334:9:
  required from 'struct std::function<int(int, int)>::_Callable<CurriedImpl<1,
std::function<int(int, int)>, int, int>, std::__invoke_result<CurriedImpl<1,
std::function<int(int, int)>, int, int>&, int, int> >'
/opt/compiler-explorer/gcc-trunk-20210809/include/c++/12.0.0/bits/std_function.h:344:8:
  required by substitution of 'template<class _Res, class ... _ArgTypes>
template<class _Cond, class _Tp> using _Requires = typename
std::enable_if<_Cond::value, _Tp>::type [with _Cond = std::function<int(int,
int)>::_Callable<CurriedImpl<1, std::function<int(int, int)>, int, int>,
std::__invoke_result<CurriedImpl<1, std::function<int(int, int)>, int, int>&,
int, int> >; _Tp = void; _Res = int; _ArgTypes = {int, int}]'
/opt/compiler-explorer/gcc-trunk-20210809/include/c++/12.0.0/bits/std_function.h:413:9:
  required by substitution of 'template<class _Functor, class, class>
std::function<int(int, int)>::function(_Functor) [with _Functor =
CurriedImpl<1, std::function<int(int, int)>, int, int>;
<template-parameter-1-2> = void; <template-parameter-1-3> = <missing>]'
<source>:25:17:   required from 'CurriedImpl<(Depth - 1), F, Args ...>
CurriedImpl<Depth, F, Args>::operator()(const First&) [with First = int; int
Depth = 1; F = std::function<int(int, int)>; Args = {int, int}]'
<source>:49:9:   required from here
<source>:16:8: fatal error: template instantiation depth exceeds maximum of 900
(use '-ftemplate-depth=' to increase the maximum)
   16 | struct CurriedImpl : public CurriedImpl<Depth-1,F,Args...>
      |        ^~~~~~~~~~~


clang accepts it in C++11-C++20 modes.
ICC hits assert.
MSVC hits the recursiveness.

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

end of thread, other threads:[~2021-08-10  0:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-12 18:47 [Bug c++/63515] New: unused templated member can be instatiated luka.rahne at gmail dot com
2014-10-13 22:01 ` [Bug c++/63515] " luka.rahne at gmail dot com
2014-10-13 22:03 ` luka.rahne at gmail dot com
2014-10-13 22:54 ` [Bug c++/63515] Deduced number of parameters can be deduced from unrelated type luka.rahne at gmail dot com
2021-08-10  0:31 ` pinskia 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).