When I use boost 1.52.1 and gcc-4.7.1 to compile my code, the following errors appear. It seems this is conflict between boost and c++ library.
Could some know how to resolve this problem?
Many thanks for your reply.
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/math/policies
/error_handling.hpp: In function 'bool boost::math::policies::
detail::check_overflow(std::complex<T>,
R*, const char*, const Policy&)':c:\program
files\mingw64\bin\../lib/gcc/x86_64-w64 mingw32/4.7.1
/../../../../include/boost/math/policies/error_handling.hpp:583:11:
error: expected unqualified-id before numeric constant
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32
/4.7.1/../../../../include/boost/math/policies/error_handling.hpp:
584:49: error: lvalue required as unary '&' operand
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/
../../../../include/boost/math/policies/
error_handling.hpp:584:107: error: 'im' was not declared in this
scope c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32
/4.7.1/../../../../include/boost/math/policies/error_handling.
hpp: In function 'bool boost::math::policies::detail::
check_underflow(std::complex<T>, R*, const char*, const Policy&)':
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64- mingw32
/4.7.1/../../../../include/boost/math/policies
/error_handling.hpp:602:11: error: expected unqualified-id before
numeric constant c:\program files\mingw64\bin\../lib/gcc/
x86_64-w64 mingw32/4.7.1/../../../../include/boost/math/policies
/error_handling.hpp:603:50: error: lvalue required as
unary '&' operand c:\program files\mingw64\bin\../lib/gcc/
x86_64-w64 mingw32/4.7.1/../../../../include/boost/math/policies
/error_handling .hpp:603:109: error: 'im' was not declared in
this scope c:\program files\mingw64\bin\../lib/gcc
/x86_64-w64-mingw32/4.7.1/../../../../include/boost/math/policies/
error_handling.hpp: In function 'bool boost::math::policies::
detail::check_denorm(std::complex<T>, R*, const char*,
const Policy&)':c:\program files\mingw64\bin\../lib/gcc
/x86_64-w64-mingw32/4.7.1/../../../../include/boost/
math/policies/error_handling.hpp:622:11: error: expected
unqualified-id before numeric constant
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/math/policies/
error_handling.hpp:623:47: error: lvalue required as
unary '&' operand
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/math/policies/
error_handling.hpp:623:103: error: 'im' was not declared
in this scope
The error appears in the code boost\math\policy\error_handling.hpp. But I am not sure when the program cite these functions. How does this error happen?
template <class R, class T, class Policy>
inline bool check_overflow(std::complex<T> val, R* result, const
char* function, const Policy& pol)
{
typedef typename R::value_type r_type;
r_type re, im;
bool r = check_overflow<r_type>(val.real(), &re, function, pol) || check_overflow<r_type>(val.imag(), &im, function, pol);
*result = R(re, im);
return r;
}
template <class R, class T, class Policy>
inline bool check_underflow(std::complex<T> val, R* result, const char* function, const Policy& pol)
{
typedef typename R::value_type r_type;
r_type re, im;
bool r = check_underflow<r_type>(val.real(), &re, function, pol) || check_underflow<r_type>(val.imag(), &im, function, pol);
*result = R(re, im);
return r;
}
Given this two functions and this noisy error message I can say that type that was used as parameter R doesn't defines value_type. Because of that, type r_type and variables im and re is not defined. As result you get error: 'im' was not declared in this scope error.
Using only provided code I can saw that type R has this requirements:
It must define type value_type
It must have constructor R(value_type real, value_type imagine)
All this means that you use some boost library that uses internaly check_underflow/check_overflow functions incorrectly, with incompatible template argument, I guess.
Related
I am trying to build one of the cgal demos from the developer website.
I have installed cgal using brew install cgal.
I also have installed qt5 version 5.15.2 using brew install qt5
However, when I try to build a demo (I am looking at the same one given in the example $HOME/CGAL-5.2.1/examples/Triangulation_) I get a long error from make that I don't know how to interpret.
My computer is running OS X 11.0.1.
Clang is version 12.0.0
/opt/homebrew/include/QtCore/qglobal.h:667:65: error: expected '>'
typename = std::enable_if_t<std::is_arithmetic_v<T> && std::is_arithmetic_v<U> &&
^
/opt/homebrew/include/QtCore/qglobal.h:667:65: error: expected ',' or '>' in template-parameter-list
/opt/homebrew/include/QtCore/qglobal.h:668:66: error: expected unqualified-id
std::is_floating_point_v<T> == std::is_floating_point_v<U> &&
^
/opt/homebrew/include/QtCore/qglobal.h:679:35: error: no type named 'Promoted' in namespace
'QTypeTraits::detail'
using Promoted = typename detail::Promoted<T, U>::type;
~~~~~~~~~~~~~~~~~^~~~~~~~
/opt/homebrew/include/QtCore/qglobal.h:679:43: error: expected ';' after alias declaration
using Promoted = typename detail::Promoted<T, U>::type;
^
/opt/homebrew/include/QtCore/qglobal.h:691:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:693:28: error: no template named 'Promoted' in namespace 'QTypeTraits'
using P = QTypeTraits::Promoted<T, U>;
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:694:5: error: unknown type name 'P'
P _a = a;
^
/opt/homebrew/include/QtCore/qglobal.h:695:5: error: unknown type name 'P'
P _b = b;
^
/opt/homebrew/include/QtCore/qglobal.h:699:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:701:28: error: no template named 'Promoted' in namespace 'QTypeTraits'
using P = QTypeTraits::Promoted<T, U>;
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:702:5: error: unknown type name 'P'
P _a = a;
^
/opt/homebrew/include/QtCore/qglobal.h:703:5: error: unknown type name 'P'
P _b = b;
^
/opt/homebrew/include/QtCore/qglobal.h:707:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:710:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max)
~~~~~~~~~~~~~^
/opt/homebrew/include/QtCore/qglobal.h:713:31: error: no template named 'Promoted' in namespace 'QTypeTraits'
constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max)
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
A very late answer but my solution was to uninstall Qt6 so that you only have Qt5. It is possible you may have both installed. Header files from both can conflict and confuse make. To properly do so:
Find all of the Qt versions you have installed with Homebrew:
brew list | grep qt
# You should see something like "qt qt#5"
Remove qt (which is Qt6)
brew uninstall qt
You should now have only Qt5 left. Try doing the build again, see if the issue is fixed.
I have a type defined using typedef unsigned int value_t; and a function
value_t find_minimal_value(...) {
...
if(...) return numeric_limits<value_t>::max;
...
}
Compiler refuses to compile it, saying: invalid conversion from ‘int (*)()noexcept (true)’ to ‘value_t {aka int}’.
What does it mean? Looking into the numeric_limits class, the min() function should return a variable of the type passed to it via template typename, so value_t in this case. So why the code doesn't compile?
std::numeric_limits::max() is a function, so you need to return the result of its invocation. That is done using the call operator:
value_t find_minimal_value() {
if (...) return numeric_limits<value_t>::max();
// ^^
}
The error message meant that it couldn't convert a function pointer (i.e int (*)() to unsigned int.
I run into trouble by defining a data type as a result of an operation.
In the following example I have to Instances of a template class which have the
template type "int".
I expect that the following expression results to int, but it did not!
typename A and B are both int
decltype( declval<A>+declval<B>)
Here is the full example:
#include <utility>
using namespace std;
template <typename T>
class AV
{
};
template <typename T>
class Term
{
};
template <class A, class B>
auto operator +( AV<A>& a, AV<B>& b )->Term< int >
{
Term< decltype(declval<A>+declval<B>) >t(&a,&b);
// ~~~~~~~~~~~~~~~~~~~~~~ invalid operands of types
// '<unresolved overloaded function type>
return t;
}
int main()
{
AV<int> a;
AV<int> b;
Term<int> x(a+b);
}
results in the following error ( gcc 4.8.2 )
main.cpp: In instantiation of 'Term<int> operator+(AV<A>&, AV<B>&) [with A = int; B = int]':
main.cpp:47:23: required from here
main.cpp:39:111: error: invalid operands of types '<unresolved overloaded function type>' and '<unresolved overloaded function type>' to binary 'operator+'
template <class A, class B> auto operator +( AV<A>& a, AV<B>& b )->Term< int > { Term< decltype(declval<A>+declval<B>) >t(&a,&b); return t; }
^
main.cpp:39:111: error: invalid operands of types '<unresolved overloaded function type>' and '<unresolved overloaded function type>' to binary 'operator+'
make: *** [go] Error 1
declval<T> is a function. you have to call it, to form value expressions to give to decltype
try
Term< decltype(declval<A>()+declval<B>()) >t(&a,&b);
I'm tracking down a C++ compiler error which I can't figure out. I've reduced it to this code:
#include <boost/config.hpp>
#include <boost/type_traits/remove_reference.hpp>
template<typename T> inline const T bar( T in )
{
typedef BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type nonref;
const nonref* inPtr = ∈
return *inPtr;
}
class Foo
{
};
int main()
{
Foo foo;
const Foo& ref = bar< Foo& >( foo );
}
which results in:
tt.cpp: In function ‘const T bar(T) [with T = Foo&]’:
tt.cpp:19:39: instantiated from here
tt.cpp:9:13: error: invalid initialization of reference of type ‘Foo&’ from expression of type ‘const nonref {aka const Foo}’
What's the actual issue here? Why is the const missing in the return value? I need the remove_reference since the actual code requires it.
Applying const to a reference type does nothing. You need to make the template argument const foo &, or else remove the reference and then add back both const and the reference in the function signature itself.
See also When should I use remove_reference and add_reference? particularly the second paragraph.
Using VisualStudio 2008 I get the following error
error C2440: 'return' : cannot convert from 'const nonref' to 'Foo &'
Changing bat to
template<typename T> inline const typename boost::remove_reference<T>::type& bar( T in )
{
typedef BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type nonref;
const nonref* inPtr = ∈
return *inPtr;
}
fixes this and the code compiles.
Returning const T from your function doesn't do what you are expecting. From your code I understand that you expect it to return const Foo&, which is a reference to an immutable object of type Foo.
But when T is Foo&, the expression const T means an immutable reference to an object of type Foo. Since the references are always immutable, the const part is just dropped (according to the paragraph 8.3.2 of the spec)! That is, your function returns Foo& and not const Foo& and that's what the compiler tries to tell you.
I have a template class where I want to use objects of that class (along with the parameterized type) inside a map. So far this is the solution that I've been able to arrive at:
class IStatMsg;
template <typename T>
class ITier
{
public:
// Methods
ITier(TierType oType) : o_Type(oType){};
virtual ~ITier(){};
typename ITier<T> ParamITier; // line 60
ITier* Get(T oKey)
{
std::map<T, ParamITier*>::iterator it = map_Tiers.find(oKey); // line 64
if (it != map_Tiers.end())
return it->second;
return NULL;
}
void Set(T oKey, ITier* pTier)
{
map_Tiers.insert(pair<T, ParamITier*>(oKey, pTier)); // line 74
}
TierType GetType() { return o_Type; }
protected:
// Methods
// Attributes
std::map<T, ParamITier*> map_Tiers; // line 83
TierType o_Type;
private:
// Methods
// Attributes
};
But when I try to compile this code I get a long list of errors:
/home/gayanm/street/src/QueryServer_NEW/ITier.h:60:
error: expected nested-name-specifier
/home/gayanm/street/src/QueryServer_NEW/ITier.h:60:
error: ITier<T>' specified as
declarator-id
/home/gayanm/street/src/QueryServer_NEW/ITier.h:60:
error: perhaps you wantITier'
for a constructor
/home/gayanm/street/src/QueryServer_NEW/ITier.h:60:
error: two or more data types in
declaration of ITier<T>'
/home/gayanm/street/src/QueryServer_NEW/ITier.h:60:
error: expected;' before
"ParamITier"
/home/gayanm/street/src/QueryServer_NEW/ITier.h:83:
error: ParamITier' was not declared
in this scope
/home/gayanm/street/src/QueryServer_NEW/ITier.h:83:
error: template argument 2 is invalid
/home/gayanm/street/src/QueryServer_NEW/ITier.h:83:
error: template argument 4 is invalid
/home/gayanm/street/src/QueryServer_NEW/ITier.h:83:
error: ISO C++ forbids declaration of
map_Tiers' with no type
/home/gayanm/street/src/QueryServer_NEW/ITier.h:
In member function ITier<T>*
ITier<T>::Get(T)':
/home/gayanm/street/src/QueryServer_NEW/ITier.h:64:
error:ParamITier' undeclared (first
use this function)
/home/gayanm/street/src/QueryServer_NEW/ITier.h:64:
error: (Each undeclared identifier is
reported only once for each function
it appears in.)
/home/gayanm/street/src/QueryServer_NEW/ITier.h:64:
error: template argument 2 is invalid
/home/gayanm/street/src/QueryServer_NEW/ITier.h:64:
error: template argument 4 is invalid
/home/gayanm/street/src/QueryServer_NEW/ITier.h:64:
error: expected ;' before '::' token
/home/gayanm/street/src/QueryServer_NEW/ITier.h:66:
error:it' undeclared (first use this
function)
/home/gayanm/street/src/QueryServer_NEW/ITier.h:66:
error: request for member end' in
((ITier)this)->ITier::map_Tiers',
which is of non-class type int'
/home/gayanm/street/src/QueryServer_NEW/ITier.h:
In member functionvoid
ITier::Set(T, ITier)':
/home/gayanm/street/src/QueryServer_NEW/ITier.h:74:
error: request for member insert' in
((ITier*)this)->ITier::map_Tiers',
which is of non-class type int'
/home/gayanm/street/src/QueryServer_NEW/ITier.h:74:
error:pair' undeclared (first use
this function)
/home/gayanm/street/src/QueryServer_NEW/ITier.h:74:
error: expected primary-expression
before ',' token
/home/gayanm/street/src/QueryServer_NEW/ITier.h:74:
error: ParamITier' undeclared (first
use this function)
/home/gayanm/street/src/QueryServer_NEW/ITier.h:74:
error: expected primary-expression
before '>' token
/home/gayanm/street/src/QueryServer_NEW/ITier.h:
At global scope:
/home/gayanm/street/src/QueryServer_NEW/ITier.h:93:
error: baseITier' with
only non-default constructor in class
without a constructor
/home/gayanm/street/src/QueryServer_NEW/ITier.h:109:
error: expected class-name before '{'
token
Could you please point out how to fix these?
Thank You.
Line 60 does not access a depending name. What you use is ITier<T> of which the compiler knows it's a template given an argument. Instead of typename you want to use typedef ;)
Line 64 does access the depending name iterator which is a type-name, so you have to put typename before std::map. I put the two disambiguations, template and typename on this answer: Disambiguations of dependent names.
Line 74 would be right, if you fix the bug in Line 60, as far as i can see.
Line 83 is alright in itself as far as i can see.
Also, I would recommend that you pass const T& to the functions instead of T, since you cannot be sure (it's a template parameter!) that it'll be a "cheap" copy.
Thanks a lot litb. I was able to fix my code with the guidelines you provided.
class IStatMsg;
template <typename T>
class ITier
{
public:
// Methods
ITier(){};
ITier(TierType oType) : o_Type(oType){};
virtual ~ITier(){};
//typename ITier<T> ParamITier;
ITier<T>* Get(T oKey)
{
typename std::map<T, ITier<T>*>::iterator it = map_Tiers.find(oKey);
if (it != map_Tiers.end())
return it->second;
return NULL;
}
void Set(T oKey, ITier<T>* pTier)
{
map_Tiers.insert(std::pair<T, ITier<T>*>(oKey, pTier));
}
TierType GetType() { return o_Type; }
protected:
// Methods
// Attributes
std::map<T, ITier<T>*> map_Tiers;
TierType o_Type;
private:
// Methods
// Attributes
};