2 Replies Latest reply: Apr 7, 2014 6:31 AM by Fedor-Oracle RSS

    12.4 beta. R issues

    mplummer

      I'm reviewing C++ code in the R project (http://www.r-project.org). R itself does not use C++ but many contributed packages do, and many of these rely on the Rcpp interface between R and C++ (https://github.com/RcppCore/Rcpp ). Solaris is one of the testing platforms for R packages (http://cran.r-project.org/web/checks/check_summary.html) and it will be extremely helpful to continue to use it as people move to C++11. I understand that support for C++11 in 12.4 is currently limited, but I would like to take the opportunity to highlight some problems. I've got two clearly identified problems so far, but there will be more.


      Problem 1.

      The "using" keyword can only be used in a template definition, whereas it should also be possible to use it outside of a template as a general replacement for typedef.

       

      Input:

       

      #include <vector>
      #include <map>

       

      //OK
      template<class T>
      using IntMap  = std::map<int, T>;

       

      //Not OK
      using IntVector = std::vector<int>;

       

      Output

       

      martyn@fimbo:~/temp$ CC -c -std=c++11 using.cc

      "using.cc", line 9: Error: IntVector is not defined.

      "using.cc", line 9: Error: Use ";" to terminate declarations.

      "using.cc", line 9: Error: A declaration was expected instead of "=".

      "using.cc", line 9: Warning: declarator required in declaration.

      3 Error(s) and 1 Warning(s) detected.

       

      Both clang++ and Intel Composer XE accept the second usage.

       

      Problem 2

      The compiler is sensitive to the order of the override and noexcept keywords. Putting them in the wrong order causes a syntax error.

       

      Input

       

      class A
      {
         public:
            virtual void method_a() const noexcept;
            virtual void method_b() const noexcept;
      };

       

      class B : public A
      {
         public:
            virtual void method_a() const override noexcept; //OK
            virtual void method_b() const noexcept override; //Not OK!
      };

       

      Output:

       

      martyn@fimbo:~/temp$ CC -c -std=c++11 override.cc

      "override.cc", line 12: Error: "," expected instead of "override".

      1 Error(s) detected.

       

      Clang++ allows both orderings. The Intel C++ compiler rejects the order "override noexcept" and accepts the order "noaccept override" which is unfortunately the exact opposite of what Solaris Studio 12.4beta accepts.

        • 1. Re: 12.4 beta. R issues
          Fedor-Oracle

          > The "using" keyword can only be used in a template definition, whereas it should also be possible to use it outside of a template as a general replacement for typedef.

           

          Indeed, 12.4 Beta does not support non-template aliases. Check for this functionality in 12.4 Beta Refresh when it comes out.

           

          > order of the override and noexcept keywords

          > Clang++ allows both orderings.

           

          Which clang version did you check? clang3.4 reports errors for line 11 (override noexcept)

          edg4.8 and g++4.8 do that as well.

           

          I will go check with C++11 standard and file a bug on Studio if our current behavior does not match the standard.

           

          regards,

          __Fedor.

          • 2. Re: 12.4 beta. R issues
            Fedor-Oracle

            Bug report filed: 18527257 - C++11 override + noexcept parsing is wrong.