Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_PDCLIB_Noreturn not effective in C++ code #21

Open
thrimbor opened this issue May 4, 2021 · 3 comments
Open

_PDCLIB_Noreturn not effective in C++ code #21

thrimbor opened this issue May 4, 2021 · 3 comments

Comments

@thrimbor
Copy link
Contributor

thrimbor commented May 4, 2021

In nxdk, we have been getting warnings when building libc++ about functions marked as noreturn supposedly returning. I have tracked this down to the function abort, which wasn't marked as noreturn when building C++ code. This is caused by the preprocessor code in _PDCLIB_internal.h (or _PDCLIB_aux.h in our case, we haven't rebased in a while), which relies on __STDC_VERSION__. Unfortunately, __STDC_VERSION__ is not defined in C++.

This is the problematic part:

#if __STDC_VERSION__ < 201112L
#define _PDCLIB_Noreturn
#else
#define _PDCLIB_Noreturn _Noreturn
#endif

I checked how the compiler handles this, and it evaluates the __STDC_VERSION__ < 201112L condition to true, thereby not marking the functions as noreturn despite the compiler supporting it.

I replaced it with the following code, which fixes the warnings mentioned above:

#if defined(__cplusplus) && __cplusplus >= 201103L
#define _PDCLIB_Noreturn [[noreturn]]
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define _PDCLIB_Noreturn _Noreturn
#else
#define _PDCLIB_Noreturn
#endif

There are other uses of __STD_VERSION__ in PDCLib that might need similar treatment.

@DevSolar
Copy link
Owner

I will make this change for now. I will have to think a bit about any effects that might arise from the PDCLib code being compiled with _Noreturn (or nothing at all), but then used with [[noreturn]]...

DevSolar pushed a commit that referenced this issue May 15, 2021
@JayFoxRox
Copy link

Should be closed by 068f3b5 and 13217c5; please verify and close the issue.

@DevSolar
Copy link
Owner

I will keep this open until I have had a good look at the implications of mixing _Noreturn and [[noreturn]], and at other instances of STDC_VERSION use. The immediate issue is resolved though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants