public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107615] New: Segfault on accessing to methods of optional class through member pointer
@ 2022-11-10 14:49 socurahlem at yandex dot ru
  2022-11-10 16:26 ` [Bug c++/107615] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: socurahlem at yandex dot ru @ 2022-11-10 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107615
           Summary: Segfault on accessing to methods of optional class
                    through member pointer
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: socurahlem at yandex dot ru
  Target Milestone: ---

Example link: https://godbolt.org/z/K7bqeh9sG

If we access methods of optional class through pointer to member, the program
exited with segfault. I tried the example with previous versions of gcc and got
correct result. With clang the same

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

* [Bug c++/107615] Segfault on accessing to methods of optional class through member pointer
  2022-11-10 14:49 [Bug c++/107615] New: Segfault on accessing to methods of optional class through member pointer socurahlem at yandex dot ru
@ 2022-11-10 16:26 ` pinskia at gcc dot gnu.org
  2022-11-10 16:29 ` pinskia at gcc dot gnu.org
  2022-11-10 16:53 ` socurahlem at yandex dot ru
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-10 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 53874
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53874&action=edit
testcase

Next time please attach the testcase instead of just linking to godbolt.

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

* [Bug c++/107615] Segfault on accessing to methods of optional class through member pointer
  2022-11-10 14:49 [Bug c++/107615] New: Segfault on accessing to methods of optional class through member pointer socurahlem at yandex dot ru
  2022-11-10 16:26 ` [Bug c++/107615] " pinskia at gcc dot gnu.org
@ 2022-11-10 16:29 ` pinskia at gcc dot gnu.org
  2022-11-10 16:53 ` socurahlem at yandex dot ru
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-10 16:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With -W -Wall I get
<source>: In function 'int main()':
<source>:17:39: warning: 'aStr' is used uninitialized [-Wuninitialized]
   17 |     std::cout << (aClass->*aStr).value() << std::endl;;
      |                  ~~~~~~~~~~~~~~~~~~~~~^~
<source>:14:15: note: 'aStr' was declared here
   14 |     A::member aStr;
      |               ^~~~

The code is undefined because of the uninitialized variable.

Once you initialize it, the code works as expected:
    A::member aStr = &A::str;

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

* [Bug c++/107615] Segfault on accessing to methods of optional class through member pointer
  2022-11-10 14:49 [Bug c++/107615] New: Segfault on accessing to methods of optional class through member pointer socurahlem at yandex dot ru
  2022-11-10 16:26 ` [Bug c++/107615] " pinskia at gcc dot gnu.org
  2022-11-10 16:29 ` pinskia at gcc dot gnu.org
@ 2022-11-10 16:53 ` socurahlem at yandex dot ru
  2 siblings, 0 replies; 4+ messages in thread
From: socurahlem at yandex dot ru @ 2022-11-10 16:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Danil Kolotushkin <socurahlem at yandex dot ru> ---
Oh, sorry!
Pointers to the members are a bit confusing for me. Interestingly, previous
versions of gcc and clang work fine in that case. I added more fields to the
object, and it seems that they are by default pointing to the first member
which has this type. With the first type different (for example integer) clang
works fine, but doesn't print anything and gcc exits with segfault. Quite
interesting.

Thank you very much for your answer, Andrew! :)

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 14:49 [Bug c++/107615] New: Segfault on accessing to methods of optional class through member pointer socurahlem at yandex dot ru
2022-11-10 16:26 ` [Bug c++/107615] " pinskia at gcc dot gnu.org
2022-11-10 16:29 ` pinskia at gcc dot gnu.org
2022-11-10 16:53 ` socurahlem at yandex dot ru

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