Skip to content

Commit ab379a3

Browse files
author
ripley
committed
ensure noreturn attribute is set on Rf_error in C++
git-svn-id: https://svn.r-project.org/R/trunk@87911 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 6c1de05 commit ab379a3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

doc/NEWS.Rd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@
389389
\item There are a new functions \code{asRboolean} and
390390
\code{asBool}, variants of \code{asLogical} more suited to
391391
converting logical arguments to \code{Rboolean} or to \code{bool}.
392+
393+
\item Header \file{R_exts/Error.h} now ensures that
394+
\code{Rf_error} and similar are maeked with the \code{noreturn}
395+
attribute from C++ under all compilers.
392396
}
393397
}
394398

src/include/R_ext/Error.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifndef R_ERROR_H_
2727
#define R_ERROR_H_
2828

29-
#include <R_ext/Print.h>
29+
#include <R_ext/Print.h> // for R_PRINTF_FORMAT
3030

3131
#ifdef __cplusplus
3232
extern "C" {
@@ -40,7 +40,7 @@ extern "C" {
4040
*/
4141
#if defined NORET
4242
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202301L)
43-
// gcc 15 and clang 19/20
43+
// gcc 15 and clang 19-
4444
# define NORET [[noreturn]]
4545
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201102L
4646
# define NORET _Noreturn
@@ -52,10 +52,19 @@ extern "C" {
5252
# define NORET
5353
#endif
5454

55+
#ifdef __cplusplus
56+
// Only supported in C++ >= 11, but that is all current R supports
57+
// Defining NORET caused conflict in many C++-using packages
58+
[[noreturn]] void Rf_error(const char *, ...) R_PRINTF_FORMAT(1, 2);
59+
60+
[[noreturn]] void UNIMPLEMENTED(const char *);
61+
[[noreturn]] void WrongArgCount(const char *);
62+
#else
5563
NORET void Rf_error(const char *, ...) R_PRINTF_FORMAT(1, 2);
5664

5765
NORET void UNIMPLEMENTED(const char *);
5866
NORET void WrongArgCount(const char *);
67+
#endif
5968

6069
void Rf_warning(const char *, ...) R_PRINTF_FORMAT(1,2);
6170

0 commit comments

Comments
 (0)