Skip to content

Commit 36a2244

Browse files
committed
Switch to size_t to avoid conversion warnings from clang++-17
1 parent 5e8e589 commit 36a2244

File tree

5 files changed

+65
-62
lines changed

5 files changed

+65
-62
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
* README.md: Remove link references to StackOverflow
44
* inst/NEWS.Rd: Idem
5+
* inst/include/Rcpp/Module.h (S4_CppOverloadedMethods): Add cast to int
6+
to avoid warnings under 'clang++-17 -Wconversion -Wno-sign-conversion'
7+
* inst/include/Rcpp/vector/Vector.h (Vector): Idem
8+
* inst/include/Rcpp/module/class.h: Switch variable to size_t to avoid
9+
to avoid warnings under 'clang++-17 -Wconversion -Wno-sign-conversion'
10+
* inst/tinytest/testRcppClass/src/init.c: Add void to signature
511

612
2024-05-26 Dirk Eddelbuettel <[email protected]>
713

inst/include/Rcpp/Module.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
//
1+
32
// Module.h: Rcpp R/C++ interface class library -- Rcpp modules
43
//
54
// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
@@ -105,21 +104,21 @@ namespace Rcpp {
105104
class CppFunctionN : public CppFunction {
106105
public:
107106
CppFunctionN(RESULT_TYPE (*fun)(T...), const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun) {}
108-
107+
109108
SEXP operator()(SEXP* args) {
110109
BEGIN_RCPP
111110
return call<decltype(ptr_fun), RESULT_TYPE, T...>(ptr_fun, args);
112111
END_RCPP
113112
}
114-
113+
115114
inline int nargs() { return sizeof...(T); }
116115
inline void signature(std::string& s, const char* name) { Rcpp::signature<RESULT_TYPE, T...>(s, name); }
117116
inline DL_FUNC get_function_ptr() { return (DL_FUNC)ptr_fun; }
118117

119118
private:
120119
RESULT_TYPE (*ptr_fun)(T...);
121120
};
122-
121+
123122
template <typename RESULT_TYPE, typename... T>
124123
class CppFunction_WithFormalsN : public CppFunctionN<RESULT_TYPE, T...> {
125124
public:
@@ -351,7 +350,7 @@ namespace Rcpp{
351350
typedef std::vector<signed_method_class*> vec_signed_method ;
352351

353352
S4_CppOverloadedMethods( vec_signed_method* m, const XP_Class& class_xp, const char* name, std::string& buffer ) : Reference( "C++OverloadedMethods" ){
354-
int n = m->size() ;
353+
int n = static_cast<int>(m->size()) ;
355354
Rcpp::LogicalVector voidness(n), constness(n) ;
356355
Rcpp::CharacterVector docstrings(n), signatures(n) ;
357356
Rcpp::IntegerVector nargs(n) ;
@@ -405,10 +404,10 @@ namespace Rcpp{
405404
private:
406405
Method met;
407406
};
408-
407+
409408
template <typename Class, typename RESULT_TYPE, typename... T>
410409
using CppMethodN = CppMethodImplN<false, Class, RESULT_TYPE, T...>;
411-
410+
412411
template <typename Class, typename RESULT_TYPE, typename... T>
413412
using const_CppMethodN = CppMethodImplN<true, Class, RESULT_TYPE, T...>;
414413

@@ -435,10 +434,10 @@ namespace Rcpp{
435434
private:
436435
Method met;
437436
};
438-
437+
439438
template <typename Class, typename RESULT_TYPE, typename... T>
440439
using Pointer_CppMethodN = Pointer_CppMethodImplN<false, Class, RESULT_TYPE, T...>;
441-
440+
442441
template <typename Class, typename RESULT_TYPE, typename... T>
443442
using Const_Pointer_CppMethodN = Pointer_CppMethodImplN<true, Class, RESULT_TYPE, T...>;
444443
#else
@@ -661,4 +660,3 @@ static VARIABLE_IS_NOT_USED SEXP moduleSym = NULL;
661660
Rcpp_fast_eval( __load_module_call__, R_GlobalEnv );
662661

663662
#endif
664-

inst/include/Rcpp/module/class.h

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
//
1+
32
// class.h: Rcpp R/C++ interface class library -- Rcpp modules
43
//
54
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
@@ -136,8 +135,8 @@
136135
SEXP newInstance( SEXP* args, int nargs ){
137136
BEGIN_RCPP
138137
signed_constructor_class* p ;
139-
int n = constructors.size() ;
140-
for( int i=0; i<n; i++ ){
138+
size_t n = constructors.size() ;
139+
for( size_t i=0; i<n; i++ ){
141140
p = constructors[i];
142141
bool ok = (p->valid)(args, nargs) ;
143142
if( ok ){
@@ -148,7 +147,7 @@
148147

149148
signed_factory_class* pfact ;
150149
n = factories.size() ;
151-
for( int i=0; i<n; i++){
150+
for( size_t i=0; i<n; i++){
152151
pfact = factories[i] ;
153152
bool ok = (pfact->valid)(args, nargs) ;
154153
if( ok ){
@@ -162,15 +161,15 @@
162161
}
163162

164163
bool has_default_constructor(){
165-
int n = constructors.size() ;
164+
size_t n = constructors.size() ;
166165
signed_constructor_class* p ;
167-
for( int i=0; i<n; i++ ){
166+
for( size_t i=0; i<n; i++ ){
168167
p = constructors[i];
169168
if( p->nargs() == 0 ) return true ;
170169
}
171170
n = factories.size() ;
172171
signed_factory_class* pfact ;
173-
for( int i=0; i<n; i++ ){
172+
for( size_t i=0; i<n; i++ ){
174173
pfact = factories[i];
175174
if( pfact->nargs() == 0 ) return true ;
176175
}
@@ -182,10 +181,10 @@
182181

183182
vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( R_ExternalPtrAddr( method_xp ) ) ;
184183
typename vec_signed_method::iterator it = mets->begin() ;
185-
int n = mets->size() ;
184+
size_t n = mets->size() ;
186185
method_class* m = 0 ;
187186
bool ok = false ;
188-
for( int i=0; i<n; i++, ++it ){
187+
for( size_t i=0; i<n; i++, ++it ){
189188
if( ( (*it)->valid )( args, nargs) ){
190189
m = (*it)->method ;
191190
ok = true ;
@@ -209,10 +208,10 @@
209208

210209
vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( R_ExternalPtrAddr( method_xp ) ) ;
211210
typename vec_signed_method::iterator it = mets->begin() ;
212-
int n = mets->size() ;
211+
size_t n = mets->size() ;
213212
method_class* m = 0 ;
214213
bool ok = false ;
215-
for( int i=0; i<n; i++, ++it ){
214+
for( size_t i=0; i<n; i++, ++it ){
216215
if( ( (*it)->valid )( args, nargs) ){
217216
m = (*it)->method ;
218217
ok = true ;
@@ -231,10 +230,10 @@
231230

232231
vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( R_ExternalPtrAddr( method_xp ) ) ;
233232
typename vec_signed_method::iterator it = mets->begin() ;
234-
int n = mets->size() ;
233+
size_t n = mets->size() ;
235234
method_class* m = 0 ;
236235
bool ok = false ;
237-
for( int i=0; i<n; i++, ++it ){
236+
for( size_t i=0; i<n; i++, ++it ){
238237
if( ( (*it)->valid )( args, nargs) ){
239238
m = (*it)->method ;
240239
ok = true ;
@@ -326,41 +325,41 @@
326325
}
327326

328327
Rcpp::CharacterVector method_names(){
329-
int n = 0 ;
330-
int s = vec_methods.size() ;
328+
size_t n = 0 ;
329+
size_t s = vec_methods.size() ;
331330
typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
332-
for( int i=0; i<s; i++, ++it){
331+
for( size_t i=0; i<s; i++, ++it){
333332
n += (it->second)->size() ;
334333
}
335334
Rcpp::CharacterVector out(n) ;
336335
it = vec_methods.begin() ;
337-
int k = 0 ;
338-
for( int i=0; i<s; i++, ++it){
336+
size_t k = 0 ;
337+
for( size_t i=0; i<s; i++, ++it){
339338
n = (it->second)->size() ;
340339
std::string name = it->first ;
341-
for( int j=0; j<n; j++, k++){
340+
for( size_t j=0; j<n; j++, k++){
342341
out[k] = name ;
343342
}
344343
}
345344
return out ;
346345
}
347346

348347
Rcpp::IntegerVector methods_arity(){
349-
int n = 0 ;
350-
int s = vec_methods.size() ;
348+
size_t n = 0 ;
349+
size_t s = vec_methods.size() ;
351350
typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
352-
for( int i=0; i<s; i++, ++it){
351+
for( size_t i=0; i<s; i++, ++it){
353352
n += (it->second)->size() ;
354353
}
355354
Rcpp::CharacterVector mnames(n) ;
356355
Rcpp::IntegerVector res(n) ;
357356
it = vec_methods.begin() ;
358-
int k = 0 ;
359-
for( int i=0; i<s; i++, ++it){
357+
size_t k = 0 ;
358+
for( size_t i=0; i<s; i++, ++it){
360359
n = (it->second)->size() ;
361360
std::string name = it->first ;
362361
typename vec_signed_method::iterator m_it = (it->second)->begin() ;
363-
for( int j=0; j<n; j++, k++, ++m_it){
362+
for( size_t j=0; j<n; j++, k++, ++m_it){
364363
mnames[k] = name ;
365364
res[k] = (*m_it)->nargs() ;
366365
}
@@ -370,21 +369,21 @@
370369
}
371370

372371
Rcpp::LogicalVector methods_voidness(){
373-
int n = 0 ;
374-
int s = vec_methods.size() ;
372+
size_t n = 0 ;
373+
size_t s = vec_methods.size() ;
375374
typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
376-
for( int i=0; i<s; i++, ++it){
375+
for( size_t i=0; i<s; i++, ++it){
377376
n += (it->second)->size() ;
378377
}
379378
Rcpp::CharacterVector mnames(n) ;
380379
Rcpp::LogicalVector res(n) ;
381380
it = vec_methods.begin() ;
382-
int k = 0 ;
383-
for( int i=0; i<s; i++, ++it){
381+
size_t k = 0 ;
382+
for( size_t i=0; i<s; i++, ++it){
384383
n = (it->second)->size() ;
385384
std::string name = it->first ;
386385
typename vec_signed_method::iterator m_it = (it->second)->begin() ;
387-
for( int j=0; j<n; j++, k++, ++m_it){
386+
for( size_t j=0; j<n; j++, k++, ++m_it){
388387
mnames[k] = name ;
389388
res[k] = (*m_it)->is_void() ;
390389
}
@@ -395,21 +394,21 @@
395394

396395

397396
Rcpp::CharacterVector property_names(){
398-
int n = properties.size() ;
397+
size_t n = properties.size() ;
399398
Rcpp::CharacterVector out(n) ;
400399
typename PROPERTY_MAP::iterator it = properties.begin( ) ;
401-
for( int i=0; i<n; i++, ++it){
400+
for( size_t i=0; i<n; i++, ++it){
402401
out[i] = it->first ;
403402
}
404403
return out ;
405404
}
406405

407406
Rcpp::List property_classes(){
408-
int n = properties.size() ;
407+
size_t n = properties.size() ;
409408
Rcpp::CharacterVector pnames(n) ;
410409
Rcpp::List out(n) ;
411410
typename PROPERTY_MAP::iterator it = properties.begin( ) ;
412-
for( int i=0; i<n; i++, ++it){
411+
for( size_t i=0; i<n; i++, ++it){
413412
pnames[i] = it->first ;
414413
out[i] = it->second->get_class() ;
415414
}
@@ -418,12 +417,12 @@
418417
}
419418

420419
Rcpp::CharacterVector complete(){
421-
int n = vec_methods.size() - specials ;
422-
int ntotal = n + properties.size() ;
420+
size_t n = vec_methods.size() - specials ;
421+
size_t ntotal = n + properties.size() ;
423422
Rcpp::CharacterVector out(ntotal) ;
424423
typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
425424
std::string buffer ;
426-
int i=0 ;
425+
size_t i=0 ;
427426
for( ; i<n; ++it){
428427
buffer = it->first ;
429428
if( buffer[0] == '[' ) continue ;
@@ -459,11 +458,11 @@
459458

460459

461460
Rcpp::List fields( const XP_Class& class_xp ){
462-
int n = properties.size() ;
461+
size_t n = properties.size() ;
463462
Rcpp::CharacterVector pnames(n) ;
464463
Rcpp::List out(n) ;
465464
typename PROPERTY_MAP::iterator it = properties.begin( ) ;
466-
for( int i=0; i<n; i++, ++it){
465+
for( size_t i=0; i<n; i++, ++it){
467466
pnames[i] = it->first ;
468467
out[i] = S4_field<Class>( it->second, class_xp ) ;
469468
}
@@ -476,12 +475,12 @@
476475
#if RCPP_DEBUG_LEVEL > 0
477476
Rf_PrintValue( class_xp ) ;
478477
#endif
479-
int n = vec_methods.size() ;
478+
size_t n = vec_methods.size() ;
480479
Rcpp::CharacterVector mnames(n) ;
481480
Rcpp::List res(n) ;
482481
typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
483482
vec_signed_method* v;
484-
for( int i=0; i<n; i++, ++it){
483+
for( size_t i=0; i<n; i++, ++it){
485484
mnames[i] = it->first ;
486485
v = it->second ;
487486
res[i] = S4_CppOverloadedMethods<Class>( v , class_xp, it->first.c_str(), buffer ) ;
@@ -491,10 +490,10 @@
491490
}
492491

493492
Rcpp::List getConstructors( const XP_Class& class_xp, std::string& buffer){
494-
int n = constructors.size() ;
493+
size_t n = constructors.size() ;
495494
Rcpp::List out(n) ;
496495
typename vec_signed_constructor::iterator it = constructors.begin( ) ;
497-
for( int i=0; i<n; i++, ++it){
496+
for( size_t i=0; i<n; i++, ++it){
498497
out[i] = S4_CppConstructor<Class>( *it , class_xp, name, buffer ) ;
499498
}
500499
return out ;

inst/include/Rcpp/vector/Vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class Vector :
331331
}
332332

333333
inline iterator begin() { return cache.get() ; }
334-
inline iterator end() { return cache.get() + size() ; }
334+
inline iterator end() { return cache.get() + static_cast<int>(size()) ; }
335335
inline const_iterator begin() const{ return cache.get_const() ; }
336336
inline const_iterator end() const{ return cache.get_const() + size() ; }
337337
inline const_iterator cbegin() const{ return cache.get_const() ; }

inst/tinytest/testRcppClass/src/init.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#include <stdlib.h> // for NULL
44
#include <R_ext/Rdynload.h>
55

6-
/* FIXME:
6+
/* FIXME:
77
Check these declarations against the C/Fortran source code.
88
*/
99

1010
/* .Call calls */
11-
extern SEXP rcpp_hello_world_cpp();
12-
extern SEXP _rcpp_module_boot_NumEx();
13-
extern SEXP _rcpp_module_boot_RcppClassModule();
14-
extern SEXP _rcpp_module_boot_stdVector();
11+
extern SEXP rcpp_hello_world_cpp(void);
12+
extern SEXP _rcpp_module_boot_NumEx(void);
13+
extern SEXP _rcpp_module_boot_RcppClassModule(void);
14+
extern SEXP _rcpp_module_boot_stdVector(void);
1515

1616
static const R_CallMethodDef CallEntries[] = {
1717
{"rcpp_hello_world_cpp", (DL_FUNC) &rcpp_hello_world_cpp, 0},

0 commit comments

Comments
 (0)