public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98368] New: Seg fault on template method missing required return statement
@ 2020-12-18  4:17 kip at thevertigo dot com
  2020-12-18  9:16 ` [Bug c++/98368] " marxin at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kip at thevertigo dot com @ 2020-12-18  4:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98368
           Summary: Seg fault on template method missing required return
                    statement
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kip at thevertigo dot com
  Target Milestone: ---

Created attachment 49792
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49792&action=edit
Example to generate seg fault.

I am experiencing a core dump when attempting to compile code that is missing a
required return statement in a function that returns a non-void type.

$ g++ --version
g++ (Ubuntu 10.2.0-13ubuntu1) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Minimal attached.

$ g++ test2.cpp -o test2 -O3 -std=c++17 && ./test2
test2.cpp: In instantiation of ‘SomeTemplate<Type1, Type2>::NodeOffsetType
SomeTemplate<Type1, Type2>::Foo(const Type3&) const [with Type3 = int; Type1 =
int; Type2 = int; SomeTemplate<Type1, Type2>::NodeOffsetType = long int]’:
test2.cpp:25:16:   required from here
test2.cpp:20:1: warning: no return statement in function returning non-void
[-Wreturn-type]
   20 | }
      | ^
Segmentation fault (core dumped)

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

* [Bug c++/98368] Seg fault on template method missing required return statement
  2020-12-18  4:17 [Bug c++/98368] New: Seg fault on template method missing required return statement kip at thevertigo dot com
@ 2020-12-18  9:16 ` marxin at gcc dot gnu.org
  2020-12-18 11:36 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-12-18  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
That's expected behavior as your code triggers an undefined behavior:

$  g++ pr98368.C -std=c++17 -fsanitize=undefined,address && ./a.out 
pr98368.C: In instantiation of ‘SomeTemplate<Type1, Type2>::NodeOffsetType
SomeTemplate<Type1, Type2>::Foo(const Type3&) const [with Type3 = int; Type1 =
int; Type2 = int; SomeTemplate<Type1, Type2>::NodeOffsetType = long int]’:
pr98368.C:25:16:   required from here
pr98368.C:20:1: warning: no return statement in function returning non-void
[-Wreturn-type]
   20 | }
      | ^
pr98368.C:16:53: runtime error: execution reached the end of a value-returning
function without returning a value
    #0 0x401334 in long SomeTemplate<int, int>::Foo<int>(int const&) const
(/home/marxin/Programming/testcases/a.out+0x401334)
    #1 0x40127e in main (/home/marxin/Programming/testcases/a.out+0x40127e)
    #2 0x7ffff676e151 in __libc_start_main (/lib64/libc.so.6+0x28151)
    #3 0x4010ed in _start (/home/marxin/Programming/testcases/a.out+0x4010ed)

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

* [Bug c++/98368] Seg fault on template method missing required return statement
  2020-12-18  4:17 [Bug c++/98368] New: Seg fault on template method missing required return statement kip at thevertigo dot com
  2020-12-18  9:16 ` [Bug c++/98368] " marxin at gcc dot gnu.org
@ 2020-12-18 11:36 ` jakub at gcc dot gnu.org
  2020-12-18 18:24 ` kip at thevertigo dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-18 11:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
You can do that in C (if you ignore the return value of the function), but not
in C++, where it is UB already to fall through the end of function returning
non-void.

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

* [Bug c++/98368] Seg fault on template method missing required return statement
  2020-12-18  4:17 [Bug c++/98368] New: Seg fault on template method missing required return statement kip at thevertigo dot com
  2020-12-18  9:16 ` [Bug c++/98368] " marxin at gcc dot gnu.org
  2020-12-18 11:36 ` jakub at gcc dot gnu.org
@ 2020-12-18 18:24 ` kip at thevertigo dot com
  2020-12-18 18:25 ` jakub at gcc dot gnu.org
  2020-12-18 18:37 ` kip at thevertigo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: kip at thevertigo dot com @ 2020-12-18 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Kip Warner <kip at thevertigo dot com> ---
Sorry, the _compiler_ crashing is expected behaviour?

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

* [Bug c++/98368] Seg fault on template method missing required return statement
  2020-12-18  4:17 [Bug c++/98368] New: Seg fault on template method missing required return statement kip at thevertigo dot com
                   ` (2 preceding siblings ...)
  2020-12-18 18:24 ` kip at thevertigo dot com
@ 2020-12-18 18:25 ` jakub at gcc dot gnu.org
  2020-12-18 18:37 ` kip at thevertigo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-18 18:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Why do you think the compiler is crashing?  You are running the compiler and
then the program and the program is what is crashing.

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

* [Bug c++/98368] Seg fault on template method missing required return statement
  2020-12-18  4:17 [Bug c++/98368] New: Seg fault on template method missing required return statement kip at thevertigo dot com
                   ` (3 preceding siblings ...)
  2020-12-18 18:25 ` jakub at gcc dot gnu.org
@ 2020-12-18 18:37 ` kip at thevertigo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: kip at thevertigo dot com @ 2020-12-18 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Kip Warner <kip at thevertigo dot com> ---
*face palm* Yes, you are right! I totally forgot about the invocation at the
end of the CLI! That's what happens when I don't get enough sleep.

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

end of thread, other threads:[~2020-12-18 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18  4:17 [Bug c++/98368] New: Seg fault on template method missing required return statement kip at thevertigo dot com
2020-12-18  9:16 ` [Bug c++/98368] " marxin at gcc dot gnu.org
2020-12-18 11:36 ` jakub at gcc dot gnu.org
2020-12-18 18:24 ` kip at thevertigo dot com
2020-12-18 18:25 ` jakub at gcc dot gnu.org
2020-12-18 18:37 ` kip at thevertigo 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).