Skip to content

Commit 8dfd02a

Browse files
author
ripley
committed
use fixed-type emum where supported
git-svn-id: https://svn.r-project.org/R/trunk@87798 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent d0569b0 commit 8dfd02a

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

doc/NEWS.Rd

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
\encoding{UTF-8}
77

88
\section{\Rlogo CHANGES IN R-devel}{
9-
\subsection{SIGNIFICANT USER-VISIBLE CHANGES}{
10-
\itemize{
11-
\item .
12-
}
13-
}
9+
%% \subsection{SIGNIFICANT USER-VISIBLE CHANGES}{
10+
%% \itemize{
11+
%% \item .
12+
%% }
13+
%% }
1414

1515
\subsection{NEW FEATURES}{
1616
\itemize{
@@ -330,6 +330,21 @@
330330
\item The deprecated and seemingly never-used S-compatibility
331331
macros \code{F77_COM} and \code{F77_COMDECL} have been removed
332332
from header \file{R_ext/RS.h}.
333+
334+
\item The \code{enum} \code{Rboolean} defined in header
335+
\file{R_ext/Boolean.h} now has a fixed underlying type of
336+
\code{int} on platforms whose C compiler supports this.
337+
338+
This is a C23 feature (taken from C++11) and also supported in all
339+
C standards by some versions of \code{clang} (from \I{LLVM} and
340+
Apple).
341+
342+
A fair amount of code has assumed this: it may be changed to a
343+
smaller type in future.
344+
345+
If there were a platform which used an underlying type of a
346+
different size this would be an ABI-breaking change (but we are
347+
unaware of any such platform).
333348
}
334349
}
335350
@@ -613,8 +628,10 @@
613628
\I{Benjamin Sommer}'s report in \PR{18861} and collaboration with
614629
\I{Heather Turner} improving \code{reformulate()}.
615630

616-
\item Arguments which should be length-1 logical,
617-
e.g.\sspace{}\code{min(na.rm =)}, are checked more thoroughly.
631+
\item Arguments which should be length-1 logical are checked more
632+
thoroughly. The most commonly seen errors are in \code{unlink(,
633+
recursive)}, \code{tempdir()} and the \code{na.rm} argument of
634+
\code{max()}, \code{min()}, \code{sum()}, \dots.
618635
}
619636
}
620637
}

src/include/R_ext/Boolean.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,31 @@
2929
#undef FALSE
3030
#undef TRUE
3131

32+
#include <Rconfig.h> /* for HAVE_ENUM_BASE_TYPE */
33+
/*
34+
Setting the underlying aka base type is supported in C23, C++11
35+
and some C compilers based on clang.
36+
What matters here is the C compiler used to build R.
37+
*/
3238
#ifdef __cplusplus
3339
extern "C" {
3440
#endif
41+
#ifdef HAVE_ENUM_BASE_TYPE
42+
// Apple clang warns even in C23 mode: gcc warns about #pragma clang
43+
// LLVM clang no linger warns: we have no good way to filter Apple clang.
44+
# if defined __APPLE__ && defined __clang__
45+
# pragma clang diagnostic push
46+
# pragma clang diagnostic ignored "-Wfixed-enum-extension"
47+
# endif
48+
49+
typedef enum :int { FALSE = 0, TRUE } Rboolean; // so NOT NA
50+
51+
# if defined __APPLE__ && defined __clang__
52+
# pragma clang diagnostic pop
53+
# endif
54+
#else
3555
typedef enum { FALSE = 0, TRUE } Rboolean; // so NOT NA
56+
#endif
3657
#ifdef __cplusplus
3758
}
3859
#endif

0 commit comments

Comments
 (0)