https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61985
Bug ID: 61985
Summary: It's possible to declare a function pointer as
noreturn using the old volatile syntax but not
normally.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sstewartgallus00 at mylangara dot bc.ca
It's against the C11 standard to let people use the _Noreturn keyword on a
function pointer type. It's treated the same as the inline keyword. In my
opinion this is silly but whatever. Anyways, it is possible to declare a
function pointer as noreturn using the old volatile syntax but not using the
noreturn keyword or attribute. Eg)
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
typedef void f(void * restrict, int);
typedef volatile f next_t;
__attribute__((noinline)) noreturn void increment(void * restrict context,
next_t * next,
int xx)
{
next(context, xx + 1);
}
__attribute__((noinline)) noreturn void main_1(void * restrict context, int
xx);
__attribute__((noinline)) noreturn void main_2(void * restrict context, int
xx);
int main(void)
{
{
int value = 4;
printf("value: %i\n", value);
increment(NULL, main_1, value);
}
}
__attribute__((noinline)) noreturn void main_1(void * restrict context, int xx)
{
printf("value + 1: %i\n", xx);
increment(NULL, main_2, xx);
}
__attribute__((noinline)) noreturn void main_2(void * restrict context, int xx)
{
printf("value + 2: %i\n", xx);
exit(EXIT_FAILURE);
}