Rstan build error (new 2.26.1): validate_dims is not a member of stan::io

In my package (github: dmenne/gastempt) which builds on CRAN -possibly with an older version of rstan - now gives an error on Windows. I assume it has to do with a new version of rstan (2.26.1), because the generated h-files are markedly different from the last ones in my repository. rtools is current (gcc version 8.3.0 (Built by Jeroen for the R-project))

"C:/rtools40/mingw64/bin/"g++  -std=gnu++14 -I"C:/R/include" -DNDEBUG -I"../inst/include" -I"C:/R/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1 -I'C:/R/library/StanHeaders/include' -I'C:/R/library/rstan/include' -I'C:/R/library/BH/include' -I'C:/R/library/Rcpp/include' -I'C:/R/library/RcppEigen/include' -I'C:/R/library/RcppParallel/include'      -DRCPP_PARALLEL_USE_TBB=1 -I"C:/R/library/RcppParallel/include" -D_REENTRANT -DSTAN_THREADS     -O3  -Wno-unused-variable -Wno-ignored-attributes -Wno-attributes -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-maybe-uninitialized -c stanExports_powexp_gastro_2c.cc -o stanExports_powexp_gastro_2c.o
In file included from C:/R/library/rstan/include/rstan/stan_fit.hpp:20,
                 from C:/R/library/rstan/include/rstan/rstaninc.hpp:4,
                 from stanExports_linexp_gastro_1b.h:20,
                 from stanExports_linexp_gastro_1b.cc:5:
C:/R/library/rstan/include/rstan/io/rlist_ref_var_context.hpp: In member function 'void rstan::io::rlist_ref_var_context::validate_dims(const string&, const string&, const string&, const std::vector<long long unsigned int>&) const':
C:/R/library/rstan/include/rstan/io/rlist_ref_var_context.hpp:200:19: error: 'validate_dims' is not a member of 'stan::io'
         stan::io::validate_dims(*this, stage, name, base_type, dims_declared);
                   ^~~~~~~~~~~~~
In file included from C:/R/library/rstan/include/rstan/stan_fit.hpp:20,
                 from C:/R/library/rstan/include/rstan/rstaninc.hpp:4,
                 from stanExports_linexp_gastro_2b.h:20,
                 from stanExports_linexp_gastro_2b.cc:5:
C:/R/library/rstan/include/rstan/io/rlist_ref_var_context.hpp: In member function 'void rstan::io::rlist_ref_var_context::validate_dims(const string&, const string&, const string&, const std::vector<long long unsigned int>&) const':
C:/R/library/rstan/include/rstan/io/rlist_ref_var_context.hpp:200:19: error: 'validate_dims' is not a member of 'stan::io'
         stan::io::validate_dims(*this, stage, name, base_type, dims_declared);

Before we dive in deep in to this, tagging @hsbadr who has been working really hard on making 2.26 work. @hsbadr have you seen this when checking reverse dependencies?

This is a Stan headers compatibility issue, when the C++ code is generated by stanc3 and compiled with the old Stan headers. If you’re using the transitional version of StanHeaders 2.26.1, you need to define USE_STANC3 to access the new headers. This should be defined in the code generated by the latest version rstan::stanc (rstan 2.26.1), you can explicitly add -DUSE_STANC3 to CPPFLAGS.

utils::packageVersion("rstan")
utils::packageVersion("StanHeaders")

Thanks, it works when I put it into my global makevars.win. How to I make this self-contained in code, where changes in makevars are not always overwritten?

In another program which is on CRAN and works ok under Ubuntu, adding USE_STANC3 helped to get around the above problem, but now it chokes over another case:

   "C:/rtools40/mingw64/bin/"g++  -std=gnu++14 -I"C:/R/include" -DNDEBUG -I"../inst/include" -I"C:/R/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1 -I'C:/R/library/StanHeaders/include' -I'C:/R/library/rstan/include' -I'C:/R/library/BH/include' -I'C:/R/library/Rcpp/include' -I'C:/R/library/RcppEigen/include' -DUSE_STANC3       -DRCPP_PARALLEL_USE_TBB=1 -I"C:/R/library/RcppParallel/include" -D_REENTRANT -DSTAN_THREADS     -O3  -Wno-unused-variable -Wno-ignored-attributes -Wno-attributes -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-maybe-uninitialized -c stanExports_breath_test_1.cc -o stanExports_breath_test_1.o
   In file included from C:/R/library/rstan/include/rstan/rstaninc.hpp:4,
                    from stanExports_breath_test_1.h:20,
                    from stanExports_breath_test_1.cc:5:
   C:/R/library/rstan/include/rstan/stan_fit.hpp: In instantiation of 'class rstan::stan_fit<model_breath_test_1_namespace::model_breath_test_1, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >':
   stanExports_breath_test_1.cc:15:85:   required from here
   C:/R/library/rstan/include/rstan/stan_fit.hpp:930:9: error: cannot declare field 'rstan::stan_fit<model_breath_test_1_namespace::model_breath_test_1, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> > >::model_' to be of abstract type 'model_breath_test_1_namespace::model_breath_test_1'
      Model model_;
            ^~~~~~
   In file included from stanExports_breath_test_1.cc:5:
   stanExports_breath_test_1.h:40:7: note:   because the following virtual functions are pure within 'model_breath_test_1_namespace::model_breath_test_1':
    class model_breath_test_1
          ^~~~~~~~~~~~~~~~~~~
   In file included from C:/R/library/rstan/include/rstan/stan_fit.hpp:48,
                    from C:/R/library/rstan/include/rstan/rstaninc.hpp:4,
                    from stanExports_breath_test_1.h:20,
                    from stanExports_breath_test_1.cc:5:
   C:/R/library/StanHeaders/include/src/stan/model/model_base.hpp:63:36: note: 	'virtual std::vector<std::__cxx11::basic_string<char> > stan::model::model_base::model_compile_info() const'
      virtual std::vector<std::string> model_compile_info() const = 0;
                                       ^~~~~~~~~~~~~~~~~~
   make: *** [C:/R/etc/x64/Makeconf:227: stanExports_breath_test_1.o] Error 1
   ERROR: compilation failed for package 'breathteststan'
-  removing 'C:/Users/Dieter/AppData/Local/Temp/Rtmp4qSuld/devtools_install_10783c678af/breathteststan'

Fehler: 'col_ed' ist kein von 'namespace:cli' exportiertes Objekt
Ausf�hrung angehalten

Exited with status 1.
        stan::io::validate_dims(*this, stage, name, base_type, dims_declared);