Bug#833931: c++: Fail to build when <stdnoreturn.h> and the noreturn keyword is used
Package: g++-6
Version: 6.1.1-11
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 > y.c
#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.");
}
% gcc y.c
y.c: In function 'stop_now':
y.c:10:1: warning: 'noreturn' function does return
}
^
% ./a.out
Preparing to stop...
% c++ y.c
y.c:7:1: error: 'noreturn' does not name a type
noreturn void stop_now(int i) // or _Noreturn void stop_now(int i)
^~~~~~~~
y.c: In function 'int main()':
y.c:15:13: error: 'stop_now' was not declared in this scope
stop_now(2);
^
% clang y.c
y.c:10:1: warning: function declared 'noreturn' should not return [-Winvalid-noreturn]
}
^
1 warning generated.
%
Perhaps something that should be fixed?
--
Happy hacking
Petter Reinholdtsen
Reply to: