Overview
Features
Download
Documentation
Community
Add-Ons & Services

Error during building using Poco/Util/Units.h g++ -std=c++0x

Please post support and help requests here.

Error during building using Poco/Util/Units.h g++ -std=c++0x

Postby nmaludy » 19 Jul 2012, 00:10

I am getting a compiler error when trying to build some sample code i copied from http://pocoproject.org/docs/Poco.Util.Units.Value.html.
Below is information about the code, the error produced, and my system.

Code: Select all
#include <Poco/Util/Units.h>
#include <iostream>

int main(int argc, char *argv[])
{
  using namespace Poco::Util::Units::Values;

  std::cout << "One mile is " << km(mile(1)) << std::endl;
  // Output: One mile is 1.60934 km
  return 0;
}


Build Error
Code: Select all
In file included from ../src/main.cpp:1:0:
../include/Poco/Util/Units.h:331:25: error: expected identifier before ‘static_assert’
../include/Poco/Util/Units.h:331:25: error: expected unqualified-id before ‘static_assert’
,,/include/Poco/Util/Units.h:332:21: error: expected identifier before ‘static_assert’
../include/Poco/Util/Units.h:332:21: error: expected unqualified-id before ‘static_assert’
../include/Poco/Util/Units.h:377:16: error: expected ‘(’ before ‘<’ token
../include/Poco/Util/Units.h:377:16: error: expected primary-expression before ‘<’ token
../include/Poco/Util/Units.h:377:44: error: ‘checkConvertible’ was not declared in this scope
../include/Poco/Util/Units.h:377:60: error: expected ‘,’ before ‘;’ token
../include/Poco/Util/Units.h:377:60: error: expected string-literal before ‘;’ token
../include/Poco/Util/Units.h:377:60: error: expected ‘)’ before ‘;’ token
make[2]: *** [CMakeFiles/brokenunits.dir/main.o] Error 1
make[1]: *** [CMakeFiles/brokenunits.dir/all] Error 2
make: *** [all] Error 2


Poco Version
Code: Select all
$ cat poco-1.4.3-all/VERSION
1.4.3-all (2012-01-15)


GCC Version
Code: Select all
$ g++ --version
g++ (GCC) 4.6.1


Linux version (Scientific Linux)
Code: Select all
$ uname -sori
Linux 2.6.32.59 x86_64 GNU/Linux
Last edited by nmaludy on 19 Jul 2012, 18:21, edited 1 time in total.
nmaludy
 
Posts: 5
Joined: 27 Sep 2011, 23:33

Re: Error during building using Poco/Util/Units.h g++

Postby nmaludy » 19 Jul 2012, 18:20

Update:

Command i was using to compile:

Code: Select all
g++ -std=c++0x src/main.cpp -I'../include/


If i remove -std=c++0x everything works fine

(working compilation command)

Code: Select all
g++ src/main.cpp -I'../include/
nmaludy
 
Posts: 5
Joined: 27 Sep 2011, 23:33

Re: Error during building using Poco/Util/Units.h g++ -std=c

Postby nmaludy » 19 Jul 2012, 18:29

FIX:

It turns out static_assert is a new keyword in c++11.

To fix i changed Units.h (starting at line 331) from:

Code: Select all
   template <bool> struct static_assert;
   template <> struct static_assert<true> { };
      /// Ensures (at compile-time) that the template argument is true.

   template <typename T1, typename T2>
   struct Convertible;

   template <typename U>
   struct ScalingFactor;

   template <typename T1, typename T2>
   struct Convert3
      /// Converts T1 to T2.
      /// Stage 3 - performed after Stage 1 and Stage 2.
      /// The reason we perform Convert in stages is so that the compiler
      /// can resolve templates in the order we want it to.
   {
      template <typename V>
      static V fn(const V& v)
         /// The default implementation assumes that the two quantities are in compatible
         /// Units up to some scaling factor.  Find the scaling factor and apply it.
      {
         return v * ScalingFactor<T2>::template fn<V>() / ScalingFactor<T1>::template fn<V>();
      }
   };

   template <typename T1, typename T2>
   struct Convert2
      /// Converts T1 to T2.
      /// Template matches the first argument (T1),
      /// this is the fall-through to Convert3.
   {
      template <typename V>
      static V fn(const V& v)
      {
         return Convert3<T1,T2>::fn(v);
      }
   };

   template <typename T1, typename T2>
   struct Convert
      /// Converts T1 to T2.
      /// If you really want to implement your own conversion routine,
      /// specialize this template.
      /// The default implementation falls through to Convert2.
   {
      static_assert<Convertible<T1,T2>::Value> checkConvertible;
         /// If this fails, then T1 is not Convertible to T2:

      template <typename V>
      static V fn(const V& v)
      {
         return Convert2<T1,T2>::fn(v);
      }
   };


To the following which works just fine (changes are highlighted in bold):

template <bool> struct poco_static_assert;
template <> struct poco_static_assert<true> { };
/// Ensures (at compile-time) that the template argument is true.

template <typename T1, typename T2>
struct Convertible;

template <typename U>
struct ScalingFactor;

template <typename T1, typename T2>
struct Convert3
/// Converts T1 to T2.
/// Stage 3 - performed after Stage 1 and Stage 2.
/// The reason we perform Convert in stages is so that the compiler
/// can resolve templates in the order we want it to.
{
template <typename V>
static V fn(const V& v)
/// The default implementation assumes that the two quantities are in compatible
/// Units up to some scaling factor. Find the scaling factor and apply it.
{
return v * ScalingFactor<T2>::template fn<V>() / ScalingFactor<T1>::template fn<V>();
}
};

template <typename T1, typename T2>
struct Convert2
/// Converts T1 to T2.
/// Template matches the first argument (T1),
/// this is the fall-through to Convert3.
{
template <typename V>
static V fn(const V& v)
{
return Convert3<T1,T2>::fn(v);
}
};

template <typename T1, typename T2>
struct Convert
/// Converts T1 to T2.
/// If you really want to implement your own conversion routine,
/// specialize this template.
/// The default implementation falls through to Convert2.
{
poco_static_assert<Convertible<T1,T2>::Value> checkConvertible;
/// If this fails, then T1 is not Convertible to T2:

template <typename V>
static V fn(const V& v)
{
return Convert2<T1,T2>::fn(v);
}
};
nmaludy
 
Posts: 5
Joined: 27 Sep 2011, 23:33

Re: Error during building using Poco/Util/Units.h g++ -std=c

Postby bubianchi » 14 Nov 2014, 15:29

Hello,

But my mistake, the problem still occurs in POCO C++ 1.4.7 and is also valid for Microsoft Visual Studion 2012 and over. When the bug is expected to be fixed in the delivery?
Moreover, the test of Util\Units.h should not even compile : does it show that a test is missing for it?

regards,
bubianchi
 
Posts: 1
Joined: 14 Nov 2014, 15:19


Return to Support

Who is online

Users browsing this forum: No registered users and 4 guests