News for hackers. Stuff that matters.
Re:C, C++, x86/x64 assembly: The case of forgotten return by akkartik on Friday December 14, 2018 @07:14PM (#18686090)
My mind is blown that g++ (7.3.0) doesn't warn on this.
Re:C, C++, x86/x64 assembly: The case of forgotten return by saagarjha on Friday December 14, 2018 @07:19PM (#18686120)
It seems like GCC 8 warns me by default, so someone must have realized that this was stupid:

  $ pbpaste | g++-8 -x c++ -
  <stdin>: In function 'color* create_color(int, int, int)':
  <stdin>:19:1: warning: no return statement in function returning non-void [-Wreturn-type]
Re:C, C++, x86/x64 assembly: The case of forgotten return by gumby on Friday December 14, 2018 @08:07PM (#18686349)
That is the correct behavior for c.

But you mentioned g++: not sure when this became invalid in c++ but for me g++ -std=17 warns by default (though we compile everything with maximum possible warnings already)

Re:C, C++, x86/x64 assembly: The case of forgotten return by kazinator on Friday December 14, 2018 @08:30PM (#18686445)
From an ISO C conformance viewpoint, it is neither "correct" nor "incorrect" to fail to generate a diagnostic that is not required by ISO C.

In the ISO C++ language, I vaguely seem to recall ("I could have sworn that") that failing to return a value from a function is a diagnosable semantic rule violation. And that it has been for a very long time.

So I fully sympathize with the "mind is blown" comment in grandparent.

Hey, g++ -pedantic catches some important semicolon trespasses, though:

  noreturn.cc:19:2: warning: extra ‘;’ [-pedantic]
  noreturn.cc:25:2: warning: extra ‘;’ [-pedantic]
:)