openpharma/mmrm

Clean up C++ compiler warnings

danielinteractive opened this issue · 4 comments

Motivation is to clean up the compilation log as much as possible and maybe to prevent failures with higher versions of the compilers.

To do:

  • Collect and fix compiler warnings on different systems in turn
    • Mac
    • Ubuntu
    • Windows

Try to fix them, either

  • here
  • or in TMB
  • or in RcppEigen (which is probably more complicated ...)

On Mac:

  • TMB: see kaskr/adcomp#383 and kaskr/adcomp#384
    • /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/TMB/include/TMBad/TMBad.cpp:4324:10: warning: variable 'total' set but not used [-Wunused-but-set-variable]
    • /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/TMB/include/cppad/ode_gear.hpp:489:6: warning: variable 'sign' set but not used [-Wunused-but-set-variable]
    • /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/TMB/include/cppad/romberg_mul.hpp:277:10: warning: variable 'pow2' set but not used [-Wunused-but-set-variable]
    • Not a compiler warning, but from R CMD check: File ‘mmrm/libs/mmrm.so’: Found ‘__ZNSt3__14coutE’, possibly from ‘std::cout’ (C++), Object: ‘tmb.o’, I guess this was because I used an install from github for TMB, on CRAN this seems removed, see https://github.com/kaskr/adcomp/blob/3087bddae5d25c821a03a426e9a91483c8c6cd5c/TMB/NEWS#L476
  • mmrm: see #335
    • something about delete called on lower_chol_base with non-virtual destructor:
      • /opt/homebrew/opt/llvm@13/bin/../include/c++/v1/__memory/unique_ptr.h:57:5: warning: delete called on 'lower_chol_base' that is abstract but has non-virtual destructor [-Wdelete-abstract-non-virtual-dtor]
      • /opt/homebrew/opt/llvm@13/bin/../include/c++/v1/__memory/unique_ptr.h:57:5: warning: delete called on non-final 'lower_chol_spatial' that has virtual functions but non-virtual destructor [-Wdelete-non-abstract-non-virtual-dtor]
      • /opt/homebrew/opt/llvm@13/bin/../include/c++/v1/__memory/unique_ptr.h:57:5: warning: delete called on 'lower_chol_baseTMBad::global::ad_aug' that is abstract but has non-virtual destructor [-Wdelete-abstract-non-virtual-dtor]
      • I guess we just need to add virtual destructor to https://github.com/openpharma/mmrm/blob/main/src/chol_cache.h#L9
    • unused variables in predict.cpp:
      • 35:7: warning: unused variable 'theta_one_group_size' [-Wunused-variable]
        int theta_one_group_size = n_theta / n_groups;
        ^
      • 36:7: warning: unused variable 'p' [-Wunused-variable]
        int p = x.cols();
        ^
      • 27:7: warning: unused variable 'n_observations' [-Wunused-variable]
        int n_observations = x_matrix.rows();
      • 33:7: warning: unused variable 'n_theta' [-Wunused-variable]
        int n_theta = theta.size();

Mac is clean now. Yay!

On Ubuntu:

  • Get a lot of -Wignored-attributes warnings from Eigen. These very likely cannot be fixed, see e.g. RcppCore/RcppEigen#59. Therefore disabling with below ~/.R/Makevars.
  • With that it is clean then!

~/.R/Makevars:

CFLAGS = -Wno-ignored-attributes
CXXFLAGS = -Wno-ignored-attributes
CXX11FLAGS = -Wno-ignored-attributes
CXX14FLAGS = -Wno-ignored-attributes
CXX17FLAGS = -Wno-ignored-attributes
CXX20FLAGS = -Wno-ignored-attributes

(I tried to simplify this but somehow it did not work)

On Windows:

  • First check what is your home directory. Best with: Sys.getenv("HOME").
  • Then in there define the file Makevars.win in the .R folder (so similar as on Ubuntu but it needs to have the win extension).
  • Hitting the error file too big during compilation with too many sections can be solved with additional flag -Wa,-mbig-obj
  • And then it is clean, yay!

~/.R/Makevars.win:

CFLAGS = -Wa,-mbig-obj -Wno-ignored-attributes
CXXFLAGS = -Wa,-mbig-obj -Wno-ignored-attributes
CXX11FLAGS = -Wa,-mbig-obj -Wno-ignored-attributes
CXX14FLAGS = -Wa,-mbig-obj -Wno-ignored-attributes
CXX17FLAGS = -Wa,-mbig-obj -Wno-ignored-attributes
CXX20FLAGS = -Wa,-mbig-obj -Wno-ignored-attributes