Skip to main content
CTapp.1
Senior III
September 23, 2024
Question

_Noreturn is reported as a syntax error

  • September 23, 2024
  • 5 replies
  • 1357 views

A syntax error is reported against the _Noreturn specified when a function is declared _Noreturn:

_Noreturn void doesNotReturn( void )
{
 while ( 1 ) ;
}

 The compiler has been configured for C18 and the code compiles.

Can I get this to be accepted by changing a setting, or does this require an update to the Eclipse version used by the IDE?

This topic has been closed for replies.

5 replies

Andrew Neil
Super User
September 23, 2024

@CTapp.1 wrote:

A syntax error is reported against the _Noreturn specified when a function is declared _Noreturn:


Where, exactly, is that error reported - is it a compiler error, or an IDE/editor error?

What happens if you use noreturn (all lowercase) instead?

https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Function-Attributes.html#:~:text=len)%0A%20%20%20%20%20%20%20%20%20%20%09__attribute__((nonnull))%3B-,noreturn,-A%20few%20standard

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
September 23, 2024

This will work in GCC:

__attribute__((noreturn)) void does_not_return() {
 while (1);
}

Or you can use the macros defined in the headers:

__NO_RETURN void does_not_return() {
 while (1);
}

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
CTapp.1
CTapp.1Author
Senior III
September 23, 2024

Thanks, they do not result in a syntax error being reported.

Unfortunately, I am writing MISRA compliant code and neither of those are MISRA compliant (use of a language extension) and a deviation is not acceptable as the language provides a compliant alternative.

All posts are made in a personal capacity. MISRA C++ Chair, MISRA C WG Member, Director The MISRA Consortium Limited (TMCL)
Pavel A.
September 23, 2024

Check the code linting settings in Eclipse (codan?)