Skip to content

[Rcpp-devel] Formatting Fixed - Clang 3.0 and 3.3 errors on sugar/set.h

10 messages · Chris Jefferson, Dirk Eddelbuettel, Thell Fowler +1 more

#
First:: Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final)
(based on LLVM 3.0)


 >> setting environment variables:
PKG_LIBS = -lmpfr -lgmp -L/home/thell/R/library/Rcpp/lib -lRcpp
-Wl,-rpath,/home/thell/R/library/Rcpp/lib
PKG_CPPFLAGS = -std=c++11

 >> LinkingTo : Rcpp
CLINK_CPPFLAGS =  -I"/home/thell/R/library/Rcpp/include"

 >> Program source :

   1 :
   2 : // includes from the plugin
   3 :
   4 : #include <cmath>
   5 : #include <iterator>
   6 : #include <RcppCommon.h>
   7 : #include <mpreal.h>
   8 :
   9 : namespace Rcpp {
  10 : template <> SEXP wrap( const mpfr::mpreal& ) ;
  11 : }
  12 :
  13 : #include <Rcpp.h>
  14 :
  15 : // Definitions from Rmpfr conversion utilities.
  16 : #if GMP_NUMB_BITS == 32
  17 :
  18 : # define R_mpfr_nr_ints nr_limbs
  19 : # define R_mpfr_exp_size 1
  20 :
  21 : #elif GMP_NUMB_BITS == 64
  22 :
  23 : # define R_mpfr_nr_ints (2*nr_limbs)
  24 : # define R_mpfr_exp_size 2
  25 :
  26 : #endif
  27 :
  28 : # define RIGHT_HALF(_LONG_) ((long long)(_LONG_) &
0x00000000FFFFFFFF)
  29 : # define LEFT_SHIFT(_LONG_) (((long long)(_LONG_)) << 32)
  30 :
  31 : namespace Rcpp {
  32 :
  33 : template<> SEXP wrap( const mpfr::mpreal& v )
  34 : {
  35 : mpfr_srcptr pv( v.mpfr_srcptr() );
  36 :
  37 : S4 vS4("mpfr1");
  38 : vS4.slot("prec") = wrap( (int)pv->_mpfr_prec );
  39 : vS4.slot("sign") = wrap( (int)pv->_mpfr_sign);
  40 :
  41 : IntegerVector d( std::ceil( (double)pv->_mpfr_prec /
(double)mp_bits_per_limb ) );
  42 : mp_size_t i = 0;
  43 :
  44 : if( GMP_NUMB_BITS == 32 ) {
  45 :
  46 : vS4.slot("exp") = wrap( (int)pv->_mpfr_exp );
  47 :
  48 : for( auto & e : d ) {
  49 : e = (int) pv->_mpfr_d[i];
  50 : ++i;
  51 : }
  52 :
  53 : } else {
  54 :
  55 : IntegerVector exp(2);
  56 : exp[0] = (int) RIGHT_HALF(pv->_mpfr_exp);
  57 : exp[1] = (int) (pv->_mpfr_exp >> 32);
  58 : vS4.slot("exp") = exp;
  59 :
  60 : for(i=0; i < d.size(); i++) {
  61 : d[2*i]  = (int) RIGHT_HALF(pv->_mpfr_d[i]);
  62 : d[2*i+1]= (int) (pv->_mpfr_d[i] >> 32);
  63 : }
  64 :
  65 : }
  66 :
  67 : vS4.slot("d") = d;
  68 : return vS4;
  69 : }
  70 :
  71 : }
  72 :
  73 :
  74 : #ifndef BEGIN_RCPP
  75 : #define BEGIN_RCPP
  76 : #endif
  77 :
  78 : #ifndef END_RCPP
  79 : #define END_RCPP
  80 : #endif
  81 :
  82 : using namespace Rcpp;
  83 :
  84 :
  85 : // user includes
  86 :
  87 :
  88 :
  89 : // declarations
  90 : extern "C" {
  91 : SEXP file34e23fb9ce5( SEXP x, SEXP prec) ;
  92 : }
  93 :
  94 : // definition
  95 :
  96 : SEXP file34e23fb9ce5( SEXP x, SEXP prec ){
  97 : BEGIN_RCPP
  98 :
  99 : using namespace mpfr;
 100 : using namespace Rcpp;
 101 :
 102 : mpreal::set_default_prec( as< unsigned long >( prec ) );
 103 : return wrap( fac_ui( as< double >( x ) ) );
 104 :
 105 : END_RCPP
 106 : }
 107 :
 108 :
Compilation argument:
 /usr/lib/R/bin/R CMD SHLIB file34e23fb9ce5.cpp 2>
file34e23fb9ce5.cpp.err.txt
"/usr/bin/clang++" -I/usr/share/R/include -DNDEBUG -std=c++11
-I"/home/thell/R/library/Rcpp/include"   -fpic  -O3 -pipe  -g  -c
file34e23fb9ce5.cpp -o file34e23fb9ce5.o
In file included from file34e23fb9ce5.cpp:13:
In file included from /home/thell/R/library/Rcpp/include/Rcpp.h:68:
In file included from
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sugar.h:25:
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:28:2: error:
invalid preprocessing directive
#elseif defined(HAS_TR1_UNORDERED_SET)
 ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:29:13: warning:
'RCPP_UNIQUE_SET' macro redefined
    #define RCPP_UNIQUE_SET std::tr1::unordered_set
            ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:26:13: note:
previous definition is here
    #define RCPP_UNIQUE_SET std::unordered_set
            ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:30:13: warning:
'RCPP_UNIQUE_MAP' macro redefined
    #define RCPP_UNIQUE_MAP std::tr1::unordered_map
            ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:27:13: note:
previous definition is here
    #define RCPP_UNIQUE_MAP std::unordered_map
            ^
file34e23fb9ce5.cpp:57:31: warning: shift count >= width of type
[-Wshift-count-overflow]
exp[1] = (int) (pv->_mpfr_exp >> 32);
                              ^  ~~
file34e23fb9ce5.cpp:62:33: warning: shift count >= width of type
[-Wshift-count-overflow]
d[2*i+1]= (int) (pv->_mpfr_d[i] >> 32);
                                ^  ~~
4 warnings and 1 error generated.
make: *** [file34e23fb9ce5.o] Error 1

ERROR(s) during compilation: source code errors or compiler
configuration errors!


================================
Now:: clang version 3.3
(http://llvm.org/git/clang.git86256af6c8515077278d0a78f183fb6d322518ac)
(
http://llvm.org/git/llvm.git 8f54a53f0ed2091e05d5ca87d239487da292cbbc)

 >> setting environment variables:
PKG_LIBS = -lmpfr -lgmp -L/home/thell/R/library/Rcpp/lib -lRcpp
-Wl,-rpath,/home/thell/R/library/Rcpp/lib
PKG_CPPFLAGS = -std=c++11

 >> LinkingTo : Rcpp
CLINK_CPPFLAGS =  -I"/home/thell/R/library/Rcpp/include"

 >> Program source :

   1 :
   2 : // includes from the plugin
   3 :
   4 : #include <cmath>
   5 : #include <iterator>
   6 : #include <RcppCommon.h>
   7 : #include <mpreal.h>
   8 :
   9 : namespace Rcpp {
  10 : template <> SEXP wrap( const mpfr::mpreal& ) ;
  11 : }
  12 :
  13 : #include <Rcpp.h>
  14 :
  15 : // Definitions from Rmpfr conversion utilities.
  16 : #if GMP_NUMB_BITS == 32
  17 :
  18 : # define R_mpfr_nr_ints nr_limbs
  19 : # define R_mpfr_exp_size 1
  20 :
  21 : #elif GMP_NUMB_BITS == 64
  22 :
  23 : # define R_mpfr_nr_ints (2*nr_limbs)
  24 : # define R_mpfr_exp_size 2
  25 :
  26 : #endif
  27 :
  28 : # define RIGHT_HALF(_LONG_) ((long long)(_LONG_) &
0x00000000FFFFFFFF)
  29 : # define LEFT_SHIFT(_LONG_) (((long long)(_LONG_)) << 32)
  30 :
  31 : namespace Rcpp {
  32 :
  33 : template<> SEXP wrap( const mpfr::mpreal& v )
  34 : {
  35 : mpfr_srcptr pv( v.mpfr_srcptr() );
  36 :
  37 : S4 vS4("mpfr1");
  38 : vS4.slot("prec") = wrap( (int)pv->_mpfr_prec );
  39 : vS4.slot("sign") = wrap( (int)pv->_mpfr_sign);
  40 :
  41 : IntegerVector d( std::ceil( (double)pv->_mpfr_prec /
(double)mp_bits_per_limb ) );
  42 : mp_size_t i = 0;
  43 :
  44 : if( GMP_NUMB_BITS == 32 ) {
  45 :
  46 : vS4.slot("exp") = wrap( (int)pv->_mpfr_exp );
  47 :
  48 : for( auto & e : d ) {
  49 : e = (int) pv->_mpfr_d[i];
  50 : ++i;
  51 : }
  52 :
  53 : } else {
  54 :
  55 : IntegerVector exp(2);
  56 : exp[0] = (int) RIGHT_HALF(pv->_mpfr_exp);
  57 : exp[1] = (int) (pv->_mpfr_exp >> 32);
  58 : vS4.slot("exp") = exp;
  59 :
  60 : for(i=0; i < d.size(); i++) {
  61 : d[2*i]  = (int) RIGHT_HALF(pv->_mpfr_d[i]);
  62 : d[2*i+1]= (int) (pv->_mpfr_d[i] >> 32);
  63 : }
  64 :
  65 : }
  66 :
  67 : vS4.slot("d") = d;
  68 : return vS4;
  69 : }
  70 :
  71 : }
  72 :
  73 :
  74 : #ifndef BEGIN_RCPP
  75 : #define BEGIN_RCPP
  76 : #endif
  77 :
  78 : #ifndef END_RCPP
  79 : #define END_RCPP
  80 : #endif
  81 :
  82 : using namespace Rcpp;
  83 :
  84 :
  85 : // user includes
  86 :
  87 :
  88 :
  89 : // declarations
  90 : extern "C" {
  91 : SEXP file34e215a2f7e7( SEXP x, SEXP prec) ;
  92 : }
  93 :
  94 : // definition
  95 :
  96 : SEXP file34e215a2f7e7( SEXP x, SEXP prec ){
  97 : BEGIN_RCPP
  98 :
  99 : using namespace mpfr;
 100 : using namespace Rcpp;
 101 :
 102 : mpreal::set_default_prec( as< unsigned long >( prec ) );
 103 : return wrap( fac_ui( as< double >( x ) ) );
 104 :
 105 : END_RCPP
 106 : }
 107 :
 108 :
Compilation argument:
 /usr/lib/R/bin/R CMD SHLIB file34e215a2f7e7.cpp 2>
file34e215a2f7e7.cpp.err.txt
"clang++" -I/usr/share/R/include -DNDEBUG -std=c++11
-I"/home/thell/R/library/Rcpp/include"   -fpic  -O3 -pipe  -g  -c
file34e215a2f7e7.cpp -o file34e215a2f7e7.o
In file included from file34e215a2f7e7.cpp:6:
In file included from /home/thell/R/library/Rcpp/include/RcppCommon.h:349:
In file included from
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sugar_forward.h:29:
In file included from
/home/thell/R/library/Rcpp/include/Rcpp/sugar/logical/logical.h:27:
/home/thell/R/library/Rcpp/include/Rcpp/sugar/logical/SingleLogicalResult.h:36:2:
error: circular inheritance between
'conversion_to_bool_is_forbidden<x>' and
'conversion_to_bool_is_forbidden<x>'
        conversion_to_bool_is_forbidden<x>{
        ^
In file included from file34e215a2f7e7.cpp:13:
In file included from /home/thell/R/library/Rcpp/include/Rcpp.h:68:
In file included from
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sugar.h:25:
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:28:2: error:
invalid preprocessing directive
#elseif defined(HAS_TR1_UNORDERED_SET)
 ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:29:13: warning:
'RCPP_UNIQUE_SET' macro redefined
    #define RCPP_UNIQUE_SET std::tr1::unordered_set
            ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:26:13: note:
previous definition is here
    #define RCPP_UNIQUE_SET std::unordered_set
            ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:30:13: warning:
'RCPP_UNIQUE_MAP' macro redefined
    #define RCPP_UNIQUE_MAP std::tr1::unordered_map
            ^
/home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:27:13: note:
previous definition is here
    #define RCPP_UNIQUE_MAP std::unordered_map
            ^
file34e215a2f7e7.cpp:57:31: warning: shift count >= width of type
[-Wshift-count-overflow]
exp[1] = (int) (pv->_mpfr_exp >> 32);
                              ^  ~~
file34e215a2f7e7.cpp:62:33: warning: shift count >= width of type
[-Wshift-count-overflow]
d[2*i+1]= (int) (pv->_mpfr_d[i] >> 32);
                                ^  ~~
4 warnings and 2 errors generated.
make: *** [file34e215a2f7e7.o] Error 1

ERROR(s) during compilation: source code errors or compiler
configuration errors!



The code compiles and works (the warnings are expected for now) using g++.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121119/49f23aba/attachment.html>
#
On 19/11/12 17:33, Thell Fowler wrote:
Without looking any deeper at this (sorry), clang doesn't not accept 
elseif, it requires elif.

gcc actually doesn't do what you expect with elseif. It just ignores it 
if the #if isn't added, and causes a compile-time error if you end up 
actually reaching that line. So in:

#if defined(X)

#elseif defined(Y)

#endif

If X is not defined, nothing is included even if Y is defined. If X is 
defined, a compile-time error always occurs.

in you want someone with gcc, clang and c++0x experience have a dig 
through these headers, I am happy to download them and have a look.

Chris
#
Chris,
On Mon, Nov 19, 2012 at 12:40 PM, Chris Jefferson <chris at bubblescope.net>wrote:

            
Sure enough.  Good eye!  I edited the sets.h and that error is gone.

After reducing the example code to::

suppressMessages( require( inline) )
suppressMessages( require( Rcpp ) )

test <- cxxfunction( sig=signature(),
               body='
                      using namespace Rcpp;
                      return R_NilValue;
                    ',
               plugin="Rcpp",
               verbose=FALSE)
#
On 19 November 2012 at 18:40, Chris Jefferson wrote:
| On 19/11/12 17:33, Thell Fowler wrote:
| >
| > /home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:28:2: error:
| > invalid preprocessing directive
| > #elseif defined(HAS_TR1_UNORDERED_SET)
| 
| Without looking any deeper at this (sorry), clang doesn't not accept 
| elseif, it requires elif.
| 
| gcc actually doesn't do what you expect with elseif. It just ignores it 
| if the #if isn't added, and causes a compile-time error if you end up 
| actually reaching that line. So in:
| 
| #if defined(X)
| 
| #elseif defined(Y)
| 
| #endif
| 
| If X is not defined, nothing is included even if Y is defined. If X is 
| defined, a compile-time error always occurs.
| 
| in you want someone with gcc, clang and c++0x experience have a dig 
| through these headers, I am happy to download them and have a look.

Very nice catch!  I shall test and fix this.

Your absent-minded typist,  Dirk
#
On 19 November 2012 at 13:02, Dirk Eddelbuettel wrote:
| On 19 November 2012 at 18:40, Chris Jefferson wrote:
| | On 19/11/12 17:33, Thell Fowler wrote:
| | >
| | > /home/thell/R/library/Rcpp/include/Rcpp/sugar/sets.h:28:2: error:
| | > invalid preprocessing directive
| | > #elseif defined(HAS_TR1_UNORDERED_SET)
| | 
| | Without looking any deeper at this (sorry), clang doesn't not accept 
| | elseif, it requires elif.
| | 
| | gcc actually doesn't do what you expect with elseif. It just ignores it 
| | if the #if isn't added, and causes a compile-time error if you end up 
| | actually reaching that line. So in:
| | 
| | #if defined(X)
| | 
| | #elseif defined(Y)
| | 
| | #endif
| | 
| | If X is not defined, nothing is included even if Y is defined. If X is 
| | defined, a compile-time error always occurs.
| | 
| | in you want someone with gcc, clang and c++0x experience have a dig 
| | through these headers, I am happy to download them and have a look.
| 
| Very nice catch!  I shall test and fix this.

Turns out that was already fixed in SVN.  

So file this is a second known bug in 0.10.0 (with the other being Baptiste's
inability to get arma::mat wrapped automagically).

Thell, would you mind trying again after a quick 'sudo edit ...' on this file
sets.h ?

Dirk
#
On 19/11/12 18:58, Thell Fowler wrote:
This is also fixed in svn (having just checked it out).

You can locally fix it by changing line 36 from:

   conversion_to_bool_is_forbidden<x>{

to:

     forbidden_conversion<x>{
I would guess this is caused by clang 3.0's c++11 support not being very 
good. I certainly would be tempted not to try to fix it, unless there is 
a good reason for it. clang 3.2 should be out very shortly, with very 
good support.

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121119/19c798ca/attachment.html>
#
On 19 November 2012 at 19:18, Chris Jefferson wrote:
| This is also fixed in svn (having just checked it out).

Thanks for that!
 
| You can locally fix it by changing line 36 from:
| 
|   conversion_to_bool_is_forbidden<x>{
| 
| to:
| 
|     forbidden_conversion<x>{


[...]

| I would guess this is caused by clang 3.0's c++11 support not being very good.
| I certainly would be tempted not to try to fix it, unless there is a good
| reason for it. clang 3.2 should be out very shortly, with very good support.

We have the added issue that we cannot upload code requiring C++11 to the R
repo network -- it is deemed "not portable".  For that reason, our code in
Rcpp is not well tested for C++11, or at all for that matter.  

We put some hooks in two years ago and have been discouraged since.  We are
looking forward to using these features once C++11 becomes more widely
available and CRAN allows it.  For now, our hands are tied.

So I had recommended earlier that Thell just drop this.  I don;t think that
it is a fruitful avenue right now.  I am not happy about this but one can
only fight so many battles at once. 

Dirk
#
On Mon, Nov 19, 2012 at 1:18 PM, Chris Jefferson <chris at bubblescope.net>wrote:

            
Using clang 3.0 the errors regarding unordered_set not being in "std" are
fixed by including it prior to RcppCommon.

suppressMessages( require( inline) )
suppressMessages( require( Rcpp ) )

test_include <- function()
{
  plugin <- Rcpp:::Rcpp.plugin.maker(
    include.before= "#include <unordered_set>",
    LinkingTo="Rcpp" )
  settings <- plugin()
  settings
}
registerPlugin(name="test_include", plugin=test_include )

test <- cxxfunction( sig=signature(),
               body='
                      using namespace Rcpp;
                      return R_NilValue;
                    ',
               plugin="test_include",
               verbose=TRUE)


The conversion fix got things working on clang 3.3 with and without the
"-std=c++11" flag.


Thanks so much for the assists!  Now to figure out why the clang compile
time vs gcc time is so horrible.
#
On Mon, Nov 19, 2012 at 1:36 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
The future happens regardless of anything else. c++11 will end up being
used and CRAN will have to follow or be replaced, or so history shows.
#
Yes. That?s it, and this is fixed in the current devel version of Rcpp. 

Romain

Envoy? de mon iPhone

Le 19 nov. 2012 ? 19:40, Chris Jefferson <chris at bubblescope.net> a ?crit :