[cfe-dev] Invalid noreturn

Filipe Cabecinhas filcab at gmail.com
Thu Dec 17 14:16:42 PST 2009


Hi.

I was trying to compile git with clang but it yielded the "function 
declared 'noreturn' should not return" error. Here is a small test case:

[filcab at Farnsworth ~] $ cat a.c
#include <stdio.h>
#include <stdlib.h>

#define NORETURN __attribute__((__noreturn__))
extern void a(void);

static NORETURN void die_builtin(int err)
{
         exit(128);
}

static NORETURN void (*die_routine)(int i) = die_builtin;

extern NORETURN void die(int err);
void die (int err)
{
   die_routine(err);
   a();
}


extern NORETURN void aaa(int err);
void aaa(int err)
{
   exit(1);
   a();
}

[filcab at Farnsworth ~] $ clang -c a.c
a.c:20:1: warning: function declared 'noreturn' should not return
       [-Winvalid-noreturn]
}
^
1 diagnostic generated.
[filcab at Farnsworth ~] $


Is this supposed to be like this? Or is it a bug? If I call a noreturn 
function pointer, I get the warning. If I call exit(), I don't.
I was expecting both to have the same behaviour.

The code where I saw this had a die() function which received a va_list. 
After calling this die() function, they "called" the macro va_close() 
and this triggered the warning.

Regards,

   F



More information about the cfe-dev mailing list