public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104487] New: The substitution in the dependent name in a trailing return type should cause recursive instantiation
@ 2022-02-10 15:00 xmh970252187 at gmail dot com
  2022-02-11  5:46 ` [Bug c++/104487] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: xmh970252187 at gmail dot com @ 2022-02-10 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104487
           Summary: The substitution in the dependent name in a trailing
                    return type should cause recursive instantiation
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xmh970252187 at gmail dot com
  Target Milestone: ---

#include <iostream>
struct C{};
template<class T>
struct anotherType{
    using type = C;
};

template<class T>
auto fun(T)->decltype(fun(typename anotherType<T>::type{})){  //#1
    return 0;
}
int fun(C){  // #2
    return 0;
}
int main(){
   fun(0);  // #3
}

GCC incorrectly accepts this case and uses `fun<int>(int)` for the function
call at `#3`. The dependent name `fun` in the trailing return type will be
looked up in the instantiation context, since the type of the argument is class
type `C`, ADL would find `#1` and `#2` for that dependent name. Overload
resolution will perform again, this causes the substitution for `#1` again,
which will repeatedly perform the aforementioned step. The instantiation should
have exceeded the limits of the implementation. 


The weird thing is that the following variant example can cause that error:  

#include <iostream>
struct C{};
template<class T>
struct anotherType{
    using type = C;
};

template<class T>
auto fun(T)->decltype(fun(typename anotherType<T>::type{})){
    return 0;
}
int fun(int){  // in the above example, parameter type is `C`
    return 0;
}
int main(){
   fun(C{});   // in the above example, the argument is of type int
}

I do not find any explicit difference for looking up the dependent name since
the argument in the dependent name is always type `C` regardless of the
argument in the call at `#3`.

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

* [Bug c++/104487] The substitution in the dependent name in a trailing return type should cause recursive instantiation
  2022-02-10 15:00 [Bug c++/104487] New: The substitution in the dependent name in a trailing return type should cause recursive instantiation xmh970252187 at gmail dot com
@ 2022-02-11  5:46 ` pinskia at gcc dot gnu.org
  2022-02-11  7:07 ` pinskia at gcc dot gnu.org
  2022-02-11  7:10 ` xmh970252187 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-11  5:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ICC and MSVC accept this also.

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

* [Bug c++/104487] The substitution in the dependent name in a trailing return type should cause recursive instantiation
  2022-02-10 15:00 [Bug c++/104487] New: The substitution in the dependent name in a trailing return type should cause recursive instantiation xmh970252187 at gmail dot com
  2022-02-11  5:46 ` [Bug c++/104487] " pinskia at gcc dot gnu.org
@ 2022-02-11  7:07 ` pinskia at gcc dot gnu.org
  2022-02-11  7:10 ` xmh970252187 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-11  7:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> ICC and MSVC accept this also.

I should say clang rejects it with recursiveness.
Also I thought I had seen this exact bug filed before but I can't find it.

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

* [Bug c++/104487] The substitution in the dependent name in a trailing return type should cause recursive instantiation
  2022-02-10 15:00 [Bug c++/104487] New: The substitution in the dependent name in a trailing return type should cause recursive instantiation xmh970252187 at gmail dot com
  2022-02-11  5:46 ` [Bug c++/104487] " pinskia at gcc dot gnu.org
  2022-02-11  7:07 ` pinskia at gcc dot gnu.org
@ 2022-02-11  7:10 ` xmh970252187 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: xmh970252187 at gmail dot com @ 2022-02-11  7:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from jim x <xmh970252187 at gmail dot com> ---
I think Clang is correct here.

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

end of thread, other threads:[~2022-02-11  7:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 15:00 [Bug c++/104487] New: The substitution in the dependent name in a trailing return type should cause recursive instantiation xmh970252187 at gmail dot com
2022-02-11  5:46 ` [Bug c++/104487] " pinskia at gcc dot gnu.org
2022-02-11  7:07 ` pinskia at gcc dot gnu.org
2022-02-11  7:10 ` xmh970252187 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).