public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113830] New: GCC accepts invalid code when instantiating the local class inside a function
@ 2024-02-08 12:41 wangbopku15 at gmail dot com
  2024-02-08 13:01 ` [Bug c++/113830] " redi at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: wangbopku15 at gmail dot com @ 2024-02-08 12:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113830
           Summary: GCC accepts invalid code when instantiating the local
                    class inside a function
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wangbopku15 at gmail dot com
  Target Milestone: ---

The following invalid code is accepted by both x86-64 gcc-trunk and x86-64
gcc-13.2:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename T> void f() {
  struct S { void g(int n = T::unknown){}; };
}
template void f<int>();

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code is invalid because the type name "int" passed in the template function
specialization does not contain the member "unknown":

It appears that if a template function has an internally defined local class
that uses a dependent name in its member function, it can cause the compiler's
name-binding process to get into trouble.

If we compile it via clang-trunk, it rejects the code with the error message:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:2:29: error: type 'int' cannot be used prior to '::' because it has no
members
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please see the godbolt to reproduce it: https://godbolt.org/z/nb3rE8s5a

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

end of thread, other threads:[~2024-02-09  9:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 12:41 [Bug c++/113830] New: GCC accepts invalid code when instantiating the local class inside a function wangbopku15 at gmail dot com
2024-02-08 13:01 ` [Bug c++/113830] " redi at gcc dot gnu.org
2024-02-08 13:08 ` mpolacek at gcc dot gnu.org
2024-02-08 13:24 ` wangbopku15 at gmail dot com
2024-02-08 13:38 ` wangbopku15 at gmail dot com
2024-02-08 13:42 ` jakub at gcc dot gnu.org
2024-02-08 13:53 ` mpolacek at gcc dot gnu.org
2024-02-08 14:14 ` wangbopku15 at gmail dot com
2024-02-08 15:01 ` redi at gcc dot gnu.org
2024-02-08 15:10 ` wangbopku15 at gmail dot com
2024-02-08 15:36 ` jakub at gcc dot gnu.org
2024-02-08 19:08 ` wangbopku15 at gmail dot com
2024-02-08 19:47 ` harald at gigawatt dot nl
2024-02-09  2:44 ` wangbopku15 at gmail dot com
2024-02-09  9:26 ` harald at gigawatt dot nl

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