ropensci / parzer

Parse geographic coordinates
https://docs.ropensci.org/parzer
Other
63 stars 6 forks source link

maybe rewrite c++ parsing from scratch #6

Closed sckott closed 5 years ago

sckott commented 5 years ago

the code included has some problems and so it may be easier to study it a bit and rewrite from scratch, while including things we want:

mpadge commented 5 years ago

Yeah, I suspect it'd be easier to rewrite from scratch. sorry for junking up this issue now, but this is a clang++ -Weverything on it, generated with the following script:

cpp_flgs <- c_flgs <- "-pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat"
setwd (here::here ("src"))
cmd_base <- paste ("-I/usr/include/R -DNDEBUG",
                  "-I\"/usr/lib/R/library/Rcpp/include\"",
                  "-I\"/usr/lib/R/library/RcppParallel/include\"",
                  "-fpic",
                  "-isystem /usr/lib/R/library/Rcpp/include",
                  "-isystem /usr/lib/R/library/RcppParallel/include",
                  "-g -O2 -fstack-protector-strong -Wformat",
                  "-Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g")

flist_cpp <- list.files (".", pattern = "\\.cpp") [c (1:6)] # [7] is RcppExports.cpp
for (f in flist_cpp)
{
    obj <- paste0 (tools::file_path_sans_ext (f), ".o")
    cmd <- paste ("clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100",
                  cmd_base, cpp_flgs, "-c", f, "-o", obj)
    message (cmd)
    system (cmd)
}

Although a lot of the warnings can be ignored, the implicit conversion and loss of precision ones really ought to be addressed. If BDR is on your case, he'll also instruct you to fix these for CRAN anyway, so you can't really ignore them. The output can be directed to a text file with system (paste0 (cmd, " 2>&1"), intern = TRUE) and looks like this

-----------------------------------------------------

clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100 -I/usr/include/R -DNDEBUG -I"/usr/lib/R/library/Rcpp/include" -I"/usr/lib/R/library/RcppParallel/include" -fpic -isystem /usr/lib/R/library/Rcpp/include -isystem /usr/lib/R/library/RcppParallel/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat -c CLongLatString.cpp -o CLongLatString.o
-----------------------------------------------------

In file included from CLongLatString.cpp:25:
./llstr.h:51:9: error: macro name is a reserved identifier [-Werror,-Wreserved-id-macro]
#define __LONG_LAT_STRING__
        ^
./llstr.h:60:26: error: declaration requires an exit-time destructor [-Werror,-Wexit-time-destructors]
const static std::string DEFAULT_COORD_FORMAT = "%H%D %m";
                         ^
./llstr.h:60:26: error: declaration requires a global destructor [-Werror,-Wglobal-constructors]
In file included from CLongLatString.cpp:29:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../include/c++/8.2.1/backward/strstream:50:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../include/c++/8.2.1/backward/backward_warning.h:32:2: error: This file includes at least one deprecated or antiquated header which   may be removed without further notice at a future date. Please use a   non-deprecated interface with equivalent functionality instead. For a   listing of replacement headers and interfaces, consult the file   backward_warning.h. To disable this warning use -Wno-deprecated. [-Werror,-W#warnings]
#warning \
 ^
CLongLatString.cpp:80:19: error: use of old-style cast [-Werror,-Wold-style-cast]
  dCoord = dSn * ((double)nD + (double)nM/60.0 + (double)nS/60.0/60.0);
                  ^       ~~
CLongLatString.cpp:80:32: error: use of old-style cast [-Werror,-Wold-style-cast]
  dCoord = dSn * ((double)nD + (double)nM/60.0 + (double)nS/60.0/60.0);
                               ^       ~~
CLongLatString.cpp:80:50: error: use of old-style cast [-Werror,-Wold-style-cast]
  dCoord = dSn * ((double)nD + (double)nM/60.0 + (double)nS/60.0/60.0);
                                                 ^       ~~
CLongLatString.cpp:172:10: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (int)(fabs(GetDecimalDegree())+ROUND_OFF);
         ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:177:10: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (int)(GetDecimalMinute());
         ^    ~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:182:10: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (int)(GetDecimalSecond() + 0.5);       // Round the seconds off
         ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:193:24: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (dC - (double)(int)dC) * 60.0;
                       ^    ~~
CLongLatString.cpp:193:16: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (dC - (double)(int)dC) * 60.0;
               ^       ~~~~~~~
CLongLatString.cpp:199:24: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (dM - (double)(int)dM) * 60.0;
                       ^    ~~
CLongLatString.cpp:199:16: error: use of old-style cast [-Werror,-Wold-style-cast]
  return (dM - (double)(int)dM) * 60.0;
               ^       ~~~~~~~
CLongLatString.cpp:240:21: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      cH = strCoord[nH];
           ~~~~~~~~ ^~
CLongLatString.cpp:248:22: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
        if (strCoord[nH] == '-')
            ~~~~~~~~ ^~
CLongLatString.cpp:264:18: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      cF = strIF[i];
           ~~~~~ ^
CLongLatString.cpp:265:21: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      cC = strCoord[i];
           ~~~~~~~~ ^
CLongLatString.cpp:237:19: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    nH = strCoord.find_first_of("NSEW", 0);
       ~ ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:238:12: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
    if (nH != string::npos)
        ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:245:21: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
      nH = strCoord.find_first_not_of(" \t", 0);
         ~ ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:246:14: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
      if (nH != string::npos)
          ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:259:16: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    nL = strIF.length();
       ~ ~~~~~~^~~~~~~~
CLongLatString.cpp:261:21: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    {   nL = strCoord.length(); }
           ~ ~~~~~~~~~^~~~~~~~
CLongLatString.cpp:295:9: error: use of old-style cast [-Werror,-Wold-style-cast]
    d = (double)(cC-'0');
        ^       ~~~~~~~~
CLongLatString.cpp:339:48: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
    n1 = strCoord.find_first_of("0123456789.", n);
                  ~~~~~~~~~~~~~                ^
CLongLatString.cpp:342:54: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      n2 = strCoord.find_first_not_of("0123456789.", n1);
                    ~~~~~~~~~~~~~~~~~                ^~
CLongLatString.cpp:345:34: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      strFloat = strCoord.substr(n1, n2-n1);
                          ~~~~~~ ^~
CLongLatString.cpp:345:40: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      strFloat = strCoord.substr(n1, n2-n1);
                          ~~~~~~     ~~^~~
CLongLatString.cpp:337:9: error: comparison of integers of different signs: 'int' and 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-compare]
  if (n < strCoord.length())
      ~ ^ ~~~~~~~~~~~~~~~~~
CLongLatString.cpp:339:19: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    n1 = strCoord.find_first_of("0123456789.", n);
       ~ ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:340:12: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
    if (n1 != string::npos)
        ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:342:21: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
      n2 = strCoord.find_first_not_of("0123456789.", n1);
         ~ ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:343:14: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
      if (n2 == string::npos)
          ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:344:31: error: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32]
      { n2 = strCoord.length()+1;       }
           ~ ~~~~~~~~~~~~~~~~~^~
CLongLatString.cpp:350:20: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    {   n = strCoord.length();  }
          ~ ~~~~~~~~~^~~~~~~~
CLongLatString.cpp:375:34: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
    n2 = strF.find_first_of('%', n2);
              ~~~~~~~~~~~~~      ^~
CLongLatString.cpp:379:31: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      { ostrmR << strF.substr(n1, n2-n1);       }
                       ~~~~~~ ^~
CLongLatString.cpp:379:37: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      { ostrmR << strF.substr(n1, n2-n1);       }
                       ~~~~~~     ~~^~~
CLongLatString.cpp:382:50: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
        np = strF.find_first_of("HDMSChdmsc%", n2+1);
                  ~~~~~~~~~~~~~                ~~^~
CLongLatString.cpp:385:21: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
          cP = strF[np];
               ~~~~ ^~
CLongLatString.cpp:392:32: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
            strP = strF.substr(n2, np+1-n2);
                        ~~~~~~ ^~
CLongLatString.cpp:392:40: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
            strP = strF.substr(n2, np+1-n2);
                        ~~~~~~     ~~~~^~~
CLongLatString.cpp:400:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, GetIntegerDegree());       }
                                      ^~~~~
CLongLatString.cpp:402:46: error: use of old-style cast [-Werror,-Wold-style-cast]
              { snprintf(sFloat, 127, sForm, (int)dCoord);      }
                                             ^    ~~~~~~
CLongLatString.cpp:402:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, (int)dCoord);      }
                                      ^~~~~
CLongLatString.cpp:404:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, GetIntegerMinute());       }
                                      ^~~~~
CLongLatString.cpp:406:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, GetIntegerSecond());       }
                                      ^~~~~
CLongLatString.cpp:412:32: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
            strP = strF.substr(n2, np+1-n2);
                        ~~~~~~ ^~
CLongLatString.cpp:412:40: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
            strP = strF.substr(n2, np+1-n2);
                        ~~~~~~     ~~~~^~~
CLongLatString.cpp:420:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, fabs(dCoord));     }
                                      ^~~~~
CLongLatString.cpp:422:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, dCoord);   }
                                      ^~~~~
CLongLatString.cpp:424:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, GetDecimalMinute());       }
                                      ^~~~~
CLongLatString.cpp:426:39: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
              { snprintf(sFloat, 127, sForm, GetDecimalSecond());       }
                                      ^~~~~
CLongLatString.cpp:432:33: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
        {       ostrmR << strF.substr(n2, strF.length()-n2);    }
                               ~~~~~~ ^~
CLongLatString.cpp:432:51: error: implicit conversion changes signedness: 'int' to 'unsigned long' [-Werror,-Wsign-conversion]
        {       ostrmR << strF.substr(n2, strF.length()-n2);    }
                                                       ~^~
CLongLatString.cpp:442:31: error: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
      { ostrmR << strF.substr(n1, strF.length()-n1);    }
                       ~~~~~~ ^~
CLongLatString.cpp:442:49: error: implicit conversion changes signedness: 'int' to 'unsigned long' [-Werror,-Wsign-conversion]
      { ostrmR << strF.substr(n1, strF.length()-n1);    }
                                               ~^~
CLongLatString.cpp:375:15: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    n2 = strF.find_first_of('%', n2);
       ~ ~~~~~^~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:376:12: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
    if (n2 != string::npos)
        ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:380:14: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
      if (n2 < strF.length()-1)
          ~~ ^ ~~~~~~~~~~~~~~~
CLongLatString.cpp:382:19: error: implicit conversion loses integer precision: 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
        np = strF.find_first_of("HDMSChdmsc%", n2+1);
           ~ ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLongLatString.cpp:383:16: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
        if (np != string::npos && np > n2)
            ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:395:18: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
            nL = strlen(sForm);
               ~ ^~~~~~~~~~~~~
CLongLatString.cpp:415:18: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
            nL = strlen(sForm);
               ~ ^~~~~~~~~~~~~
CLongLatString.cpp:433:16: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
        if (np != string::npos)
            ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:436:16: error: implicit conversion from 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') to 'int' changes value from 18446744073709551615 to -1 [-Werror,-Wconstant-conversion]
        {       n2 = string::npos;      }
                   ~ ^~~~~~~~~~~~
CLongLatString.cpp:441:14: error: comparison of integers of different signs: 'int' and 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-compare]
      if (n1 < strF.length())
          ~~ ^ ~~~~~~~~~~~~~
CLongLatString.cpp:445:13: error: comparison of integers of different signs: 'int' and 'const typename basic_string<char, char_traits<char>, allocator<char> >::size_type' (aka 'const unsigned long') [-Werror,-Wsign-compare]
  while (n2 != string::npos && n2 < strF.length());
         ~~ ^  ~~~~~~~~~~~~
CLongLatString.cpp:445:35: error: comparison of integers of different signs: 'int' and 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-compare]
  while (n2 != string::npos && n2 < strF.length());
                               ~~ ^ ~~~~~~~~~~~~~
70 errors generated.
-----------------------------------------------------

-----------------------------------------------------

clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100 -I/usr/include/R -DNDEBUG -I"/usr/lib/R/library/Rcpp/include" -I"/usr/lib/R/library/RcppParallel/include" -fpic -isystem /usr/lib/R/library/Rcpp/include -isystem /usr/lib/R/library/RcppParallel/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat -c pz_extract.cpp -o pz_extract.o
-----------------------------------------------------

pz_extract.cpp:10:13: error: no previous prototype for function 'extract' [-Werror,-Wmissing-prototypes]
std::string extract(const std::string& s) {
            ^
pz_extract.cpp:16:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
pz_extract.cpp:19:13: error: no previous prototype for function 'pz_extract' [-Werror,-Wmissing-prototypes]
std::string pz_extract(std::string x) {
            ^
pz_extract.cpp:22:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
4 errors generated.
-----------------------------------------------------

-----------------------------------------------------

clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100 -I/usr/include/R -DNDEBUG -I"/usr/lib/R/library/Rcpp/include" -I"/usr/lib/R/library/RcppParallel/include" -fpic -isystem /usr/lib/R/library/Rcpp/include -isystem /usr/lib/R/library/RcppParallel/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat -c pz_hemisphere.cpp -o pz_hemisphere.o
-----------------------------------------------------

In file included from pz_hemisphere.cpp:2:
./llstr.h:51:9: error: macro name is a reserved identifier [-Werror,-Wreserved-id-macro]
#define __LONG_LAT_STRING__
        ^
./llstr.h:60:26: error: declaration requires an exit-time destructor [-Werror,-Wexit-time-destructors]
const static std::string DEFAULT_COORD_FORMAT = "%H%D %m";
                         ^
./llstr.h:60:26: error: declaration requires a global destructor [-Werror,-Wglobal-constructors]
pz_hemisphere.cpp:6:17: error: no previous prototype for function 'pz_hemisphere' [-Werror,-Wmissing-prototypes]
CharacterVector pz_hemisphere(CharacterVector lat, CharacterVector lon, std::string format) {
                ^
pz_hemisphere.cpp:7:21: error: implicit conversion loses integer precision: 'R_xlen_t' (aka 'long') to 'const int' [-Werror,-Wshorten-64-to-32]
  const int n = lat.size();
            ~   ~~~~^~~~~~
pz_hemisphere.cpp:26:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
6 errors generated.
-----------------------------------------------------

-----------------------------------------------------

clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100 -I/usr/include/R -DNDEBUG -I"/usr/lib/R/library/Rcpp/include" -I"/usr/lib/R/library/RcppParallel/include" -fpic -isystem /usr/lib/R/library/Rcpp/include -isystem /usr/lib/R/library/RcppParallel/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat -c pz_parse_parts.cpp -o pz_parse_parts.o
-----------------------------------------------------

In file included from pz_parse_parts.cpp:2:
./llstr.h:51:9: error: macro name is a reserved identifier [-Werror,-Wreserved-id-macro]
#define __LONG_LAT_STRING__
        ^
./llstr.h:60:26: error: declaration requires an exit-time destructor [-Werror,-Wexit-time-destructors]
const static std::string DEFAULT_COORD_FORMAT = "%H%D %m";
                         ^
./llstr.h:60:26: error: declaration requires a global destructor [-Werror,-Wglobal-constructors]
pz_parse_parts.cpp:17:27: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    float minx = strCoord.GetDecimalMinute();
          ~~~~   ~~~~~~~~~^~~~~~~~~~~~~~~~~~
pz_parse_parts.cpp:18:24: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    minx = was_error ? NA_REAL : minx;
         ~             ^~~~~~~
/usr/include/R/R_ext/Arith.h:58:18: note: expanded from macro 'NA_REAL'
#define NA_REAL         R_NaReal
                        ^~~~~~~~
pz_parse_parts.cpp:19:27: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    float secx = strCoord.GetDecimalSecond();
          ~~~~   ~~~~~~~~~^~~~~~~~~~~~~~~~~~
pz_parse_parts.cpp:20:24: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    secx = was_error ? NA_REAL : secx;
         ~             ^~~~~~~
/usr/include/R/R_ext/Arith.h:58:18: note: expanded from macro 'NA_REAL'
#define NA_REAL         R_NaReal
                        ^~~~~~~~
pz_parse_parts.cpp:6:11: error: no previous prototype for function 'pz_parse_parts' [-Werror,-Wmissing-prototypes]
DataFrame pz_parse_parts(CharacterVector x, std::string format) {
          ^
pz_parse_parts.cpp:7:19: error: implicit conversion loses integer precision: 'R_xlen_t' (aka 'long') to 'const int' [-Werror,-Wshorten-64-to-32]
  const int n = x.size();
            ~   ~~^~~~~~
pz_parse_parts.cpp:29:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
10 errors generated.
-----------------------------------------------------

-----------------------------------------------------

clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100 -I/usr/include/R -DNDEBUG -I"/usr/lib/R/library/Rcpp/include" -I"/usr/lib/R/library/RcppParallel/include" -fpic -isystem /usr/lib/R/library/Rcpp/include -isystem /usr/lib/R/library/RcppParallel/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat -c pz_parse.cpp -o pz_parse.o
-----------------------------------------------------

In file included from pz_parse.cpp:2:
./llstr.h:51:9: error: macro name is a reserved identifier [-Werror,-Wreserved-id-macro]
#define __LONG_LAT_STRING__
        ^
./llstr.h:60:26: error: declaration requires an exit-time destructor [-Werror,-Wexit-time-destructors]
const static std::string DEFAULT_COORD_FORMAT = "%H%D %m";
                         ^
./llstr.h:60:26: error: declaration requires a global destructor [-Werror,-Wglobal-constructors]
pz_parse.cpp:13:22: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    float z = strLat.GetDecimalDegree();
          ~   ~~~~~~~^~~~~~~~~~~~~~~~~~
pz_parse.cpp:17:12: error: comparing floating point with == or != is unsafe [-Werror,-Wfloat-equal]
    z = (z == 0 || std::abs(z) > 90 || strLat.IsError()) ? NA_REAL : z;
         ~ ^  ~
pz_parse.cpp:17:60: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    z = (z == 0 || std::abs(z) > 90 || strLat.IsError()) ? NA_REAL : z;
      ~                                                    ^~~~~~~
/usr/include/R/R_ext/Arith.h:58:18: note: expanded from macro 'NA_REAL'
#define NA_REAL         R_NaReal
                        ^~~~~~~~
pz_parse.cpp:18:12: error: implicit conversion increases floating-point precision: 'float' to 'typename storage_type<14>::type' (aka 'double') [-Werror,-Wdouble-promotion]
    y[i] = z;
         ~ ^
pz_parse.cpp:7:15: error: no previous prototype for function 'pz_parse_lat' [-Werror,-Wmissing-prototypes]
NumericVector pz_parse_lat(CharacterVector x, std::string format) {
              ^
pz_parse.cpp:8:19: error: implicit conversion loses integer precision: 'R_xlen_t' (aka 'long') to 'const int' [-Werror,-Wshorten-64-to-32]
  const int n = x.size();
            ~   ~~^~~~~~
pz_parse.cpp:21:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
pz_parse.cpp:30:22: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    float z = strLon.GetDecimalDegree();
          ~   ~~~~~~~^~~~~~~~~~~~~~~~~~
pz_parse.cpp:33:12: error: comparing floating point with == or != is unsafe [-Werror,-Wfloat-equal]
    z = (z == 0 || strLon.IsError()) ? NA_REAL : z;
         ~ ^  ~
pz_parse.cpp:33:40: error: implicit conversion loses floating-point precision: 'double' to 'float' [-Werror,-Wconversion]
    z = (z == 0 || strLon.IsError()) ? NA_REAL : z;
      ~                                ^~~~~~~
/usr/include/R/R_ext/Arith.h:58:18: note: expanded from macro 'NA_REAL'
#define NA_REAL         R_NaReal
                        ^~~~~~~~
pz_parse.cpp:34:12: error: implicit conversion increases floating-point precision: 'float' to 'typename storage_type<14>::type' (aka 'double') [-Werror,-Wdouble-promotion]
    y[i] = z;
         ~ ^
pz_parse.cpp:24:15: error: no previous prototype for function 'pz_parse_lon' [-Werror,-Wmissing-prototypes]
NumericVector pz_parse_lon(CharacterVector x, std::string format) {
              ^
pz_parse.cpp:25:19: error: implicit conversion loses integer precision: 'R_xlen_t' (aka 'long') to 'const int' [-Werror,-Wshorten-64-to-32]
  const int n = x.size();
            ~   ~~^~~~~~
pz_parse.cpp:37:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
17 errors generated.
-----------------------------------------------------

-----------------------------------------------------

clang++ -std=gnu++11 -fsanitize=undefined -ferror-limit=100 -I/usr/include/R -DNDEBUG -I"/usr/lib/R/library/Rcpp/include" -I"/usr/lib/R/library/RcppParallel/include" -fpic -isystem /usr/lib/R/library/Rcpp/include -isystem /usr/lib/R/library/RcppParallel/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -pedantic -Werror -Wconversion -Wsign-compare -Weverything -Wno-c++98-compat -c pz_split.cpp -o pz_split.o
-----------------------------------------------------

pz_split.cpp:46:26: error: no previous prototype for function 'split' [-Werror,-Wmissing-prototypes]
std::vector<std::string> split(const std::string& input) {
                         ^
pz_split.cpp:52:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
pz_split.cpp:55:26: error: no previous prototype for function 'pz_split' [-Werror,-Wmissing-prototypes]
std::vector<std::string> pz_split(std::string x) {
                         ^
pz_split.cpp:59:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
4 errors generated.
-----------------------------------------------------

(Ping me and I'll happily edit this comment and delete all that.)

mpadge commented 5 years ago

An alternative approach might be along the lines of my generic C++ library for datetime strings here - it's all STL, so very safe, and does a better job than any current R code at auto-parsing without any need to "%m%d%YY" stuff. Adapting that to lon-lat strings would be fairly straightforward.

sckott commented 5 years ago

thanks for sharing how to do that check! agree that might as well take care of things CRAN would complain about

sckott commented 5 years ago

wrt your datetime strings parsing approach, seems worth a try, will start a new branch

sckott commented 5 years ago

probably not comletely done, but merged into master, closing this