RE: Compiler didn't error on function with no return statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> Who said it's not legal C++?

I inferred that.  Obviously, I shouldn't have.  David said that it was legal C and so I made the jump into not legal C++.

> 
> And you *do* get a warning with -Wreturn-type, but you don't get an
> error because that would reject legal programs:

My understanding was in error.  That is why I thought that I should get a warning message from the C++ compiler (without the extra step of an option to the compiler).

> 
> void f();
> 
> bool g()
> {
>   f();
> }
> 
> Is this an error?  What if f() never returns?
> 
> In C++11 we could mark f() with [[noreturn]] (like GCC's
> __attribute((noreturn))) but just because a function isn't marked
> noreturn doesn't mean it does return.

True, but that does seem to be rather poor design (I know you're giving me an example).  Probably, the language supports this because of some need which I've not run into and am unaware of its merits.

Thanks for the info.

Andy





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux