DevSolar / pdclib

The Public Domain C Library
https://pdclib.rootdirectory.de
Creative Commons Zero v1.0 Universal
224 stars 41 forks source link

_PDCLIB_Noreturn does nothing in C++11 #14

Closed thrimbor closed 4 years ago

thrimbor commented 4 years ago

The current code for PDCLIB_Noreturn seems to define it as an empty macro when building with a C++ compiler. This causes warning: function declared 'noreturn' should not return [-Winvalid-noreturn] warnings when building libc++, as it expects abort(), which is called in functions marked [[noreturn]], to come with the C++11 [[noreturn]] attribute.

I experimented with adding the following code in line 59 of _PDCLIB_int.h:

#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define _PDCLIB_Noreturn [[noreturn]]
#endif

It fixed the warnings in my tests while not negatively impacting compilation of other code.

DevSolar commented 4 years ago

Working on this uncovered a series of other issues with a C++ compile I will have to fix before I can submit it all.

DevSolar commented 4 years ago

_PDCLIB_Noreturn (leading a function declaration) resolves to the C11 keyword _Noreturn if, and only if, the compiler is running in C11 mode. This works in tandem with the header <stdnoreturn.h>. This is not something you should have to touch.

There is the creatively named _PDCLIB_NORETURN, which is trailing the same function declarations that _PDCLIB_Noreturn is leading. This is actually the older construct, added before there even was a C11. It is configured in <_PDCLIB_config.h>, to resolve to whatever your compiler needs to be informed that this function does, indeed, not return -- regardless of which mode it runs in. In the example platform, this is set to __attribute__(( noreturn )), which "does the right thing" for GCC.

For some reason this attribute was not set for the <stdlib.h> functions. I might have removed it when I added the C11 construct, or never have added it, I don't know. I'll look into how that muckup came to happen at some later time.

Long story short, the latest version (in both SVN and git) should compile cleanly for C++.