[Bug c++/89232] New: c++: Fail to build when <stdnoreturn.h> and the noreturn keyword is used
pere at hungry dot com
gcc-bugzilla@gcc.gnu.org
Thu Feb 7 07:05:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89232
Bug ID: 89232
Summary: c++: Fail to build when <stdnoreturn.h> and the
noreturn keyword is used
Product: gcc
Version: 8.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pere at hungry dot com
Target Milestone: ---
I ran into this issue while trying to prepare the coz profiler for Debian.
The <stdnoreturn.h> header file seem to be inefficient when using cc and
clang, be ignored causing an build error when using c++.
I found this example code on
<URL: http://en.cppreference.com/w/c/language/_Noreturn >, and it fail
to build with c++, but build with both cc and clang:
% cat > c++-noreturn.c <<EOF
#include <stdlib.h>
#include <stdio.h>
#include <stdnoreturn.h>
// causes undefined behavior if i <= 0
// exits if i > 0
noreturn void stop_now(int i) // or _Noreturn void stop_now(int i)
{
if (i > 0) exit(i);
}
int main(void)
{
puts("Preparing to stop...");
stop_now(2);
puts("This code is never executed.");
}
EOF
% gcc c++-noreturn.c
c++-noreturn.c: In function 'stop_now':
c++-noreturn.c:10:1: warning: 'noreturn' function does return
}
^
% ./a.out
Preparing to stop...
% c++ c++-noreturn.c
c++-noreturn.c:7:1: error: 'noreturn' does not name a type
noreturn void stop_now(int i) // or _Noreturn void stop_now(int i)
^~~~~~~~
c++-noreturn.c: In function 'int main()':
c++-noreturn.c:15:13: error: 'stop_now' was not declared in this scope
stop_now(2);
^
% clang c++-noreturn.c
c++-noreturn.c:10:1: warning: function declared 'noreturn' should not return
[-Winvalid-noreturn]
}
^
1 warning generated.
%
Perhaps something that should be fixed?
This issue is also reported as https://bugs.debian.org/833931 and has been
present since at least gcc 6. I find
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53182 related to the user of
<stdnoreturn.h>, but it seem to be a different issue.
--
Happy hacking
Petter Reinholdtsen
More information about the Gcc-bugs
mailing list