g++ error message "use 'this->equal' instead?" - c++

I am trying to use stlplus ntree class and have written a program using it, and I have no problem compiling it in a Windows environment. I tried to port it into Ubuntu, but have errors.
stlplus ntree class uses template. Here is an example of my code
ntree<rule_node_struct> t;
ntree<rule_node_struct>::iterator cur_it;
if (cur_it == t.root())
{
// do something
}
When I compiled using g++, I get the following error message
In instantiation of ‘bool stlplus::ntree_iterator::operator==(const this_iterator&) const [with T = rule_node_struct; TRef = rule_node_struct&; TPtr = rule_node_struct*; stlplus::ntree_iterator::this_iterator = stlplus::ntree_iterator]’:
/usr/lib/stlplus3-03-08/containers/ntree.tpp:133:19: error: ‘equal’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
/usr/lib/stlplus3-03-08/containers/ntree.tpp:133:19: note: declarations in dependent base ‘stlplus::safe_iterator, stlplus::ntree_node >’ are not found by unqualified lookup
/usr/lib/stlplus3-03-08/containers/ntree.tpp:133:19: note: use ‘this->equal’ instead
Why does g++ has this error while Windows Visual Studio does not?

That seems to be a bug in the ntree class, as G++ does proper two-phase lookup of symbols, while VC seems to accept the broken code. Note that earlier versions of G++ also accepted this kind of code (AFAIK) and therefore it only got fixed in the latest version in the repository. Although that version is from 2010. It seems to me that it never made it into any release, so use the HEAD version or ask them to do a release.

Related

gcc compile error with sine and boost:interval

I'm required to run some code on a linux (CentOs 6.7) server with gcc/g++ installed (7.2.0) and boost (1.66) (Edit: not only 1.66, an older version of boost interfered. Keep your machines clean guys). I specified my interval type with policies like so:
// test.cpp
#include <boost/numeric/interval.hpp>
namespace bn = boost::numeric;
namespace bi = bn::interval_lib;
using Interval = bn::interval<
double,
bi::policies<
bi::save_state<bi::rounded_transc_std<double> >,
bi::checking_base<double>
>
>;
Now I want to do some simple calculation like:
// still test.cpp
int main()
{
Interval iv_arg {1.0};
Interval res = sin(iv_arg);
}
On my local machine, a mac, compiling with clang works perfectly fine. However, as soon as I try to run it on the server, compiling with g++ -std=c++11 test.cpp I'm getting the error:
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:59: error:
'to_int' was not declared in this scope, and no declarations were
found by argument-dependent lookup at the point of instantiation
[-fpermissive] T int_down(const T& x) { this->downward(); return
to_int(x); }
~~~~~~^~~ /usr/include/boost/numeric/interval/rounded_arith.hpp:71:59: note:
declarations in dependent base
'boost::numeric::interval_lib::detail::c99_rounding' are not found by
unqualified lookup
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:59: note: use
'this->to_int' instead
There is some more info which seems irrelevant to the topic, but I can include it if it might help. I tried to google a little but couldn't find anything relevant. If possible, I would like to find a solution that doesn't require any changes on the server. Does anyone have an idea or encountered a similar problem before?
First version of boost that compiles this is 1.58
boost 1.57 ERROR
boost 1.58 OK

Error "is_enum not declared in this scope" when trying to compile my wxWidgets program

The G++ compiler shows the following errors when I try to compile:
C:\wx\include\wx\strvararg.h|350|error: 'is_enum' in namespace 'std' does not name a template type|
C:\wx\include\wx\strvararg.h|354|error: 'is_enum' was not declared in this scope|
C:\wx\include\wx\strvararg.h|354|error: template argument 1 is invalid|
I am using Code::Blocks for this, with a non-monolithic DLL build of wxWidgets.
Thanks for any help!
As Brian already indicated, you should enable C++11. There are two ways of doing this as you can see What are the differences between -std=c++11 and -std=gnu++11?.
As I remember, when compiling the whole wxWidgets library, I used -std=gnu++11 and had no problems.
Just to add to macroland comment:
You should consider upgrading to gcc version 5.2+. This version(s) does have a full set of c++11 features, whereas previous versions have them partially.

Expected nested-name-specifier

I am taking my project from my laptop to another and I encounter an error.
My project runs perfectly on my machine that I use codeblocks.
Now, I try to compile it with catkin and I get an expected nested-name-specifier before "XXX". A code snipet where this error occurs is the following
template <class T>
struct convert{
using to_int = int;
}
Outputs
expected nested-name-specifier before 'to_int'
using-decleration for non-member at class scope
expected ';' before '=' token
I get this error in multiple lines of the file and at first I thought that it was a compiler issue.
I then updated from gcc 4.6 to 4.8 using this thread as a guide but I still have the same issues. Is there a specific reason I get this error? If it's not a compiler issue what could it be?
Cheers,
Panos

C++ : Unit testing using Google Mock with Code::Blocks, MinGW and C++11

I've been trying to learn unit testing on my own following along a book.
Code in the book use the C++11 standard and have a line like this:
auto variable = function(parameter);
When I first compiled it I got this warning:
warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
No biggie, I could fix that by checking the following box in the Project->Build options... menu:
[ ] Have g++ follow the C++ 11 ISO C++ language standard [-std=c++11]
Now, however, I get new errors related to Google Mock in the gtest-port.h :
| | In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
|1719| error: '_stricmp' was not declared in this scope
| | In function 'char* testing::internal::posix::StrDup(const char*)':
|1721| error: '_strdup' was not declared in this scope
| | In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':|
|1779| error: 'fdopen' was not declared in this scope
Searching for this problem yielded little for me but I did try and define the target OS as it was a suggested solution in case it was not correctly identified automatically. Adding GTEST_OS_WINDOWS=1 and/or GTEST_OS_WINDOWS_DESKTOP=1 in the projects defines changed nothing.
I realize this is easily fixed in this instance by just providing the correct type instead of using auto but I'd like to find a solution for this if possible. Replacing auto and not having the -std=c++11 option checked makes the code work as intended so the library works.
I'm using Code::Blocks 13.12 , MinGW/g++ 4.8.1-4 and Google Mock 1.7 in Windows.
Thanks for reading =)
The answer here lies in the functions which are missing declarations: _stricmp, _strdup and fdopen. The first two are Microsoft versions of the POSIX functions stricmp and strdup. Note that you are specifying the use of the C++11 ISO standard which does not contain items in the POSIX standard. By specifying --std=gnu++11 you are telling the compiler to accept a hybrid of C++11 and POSIX along with GNU extensions.
Interestingly I cannot replicate this with GCC 4.8.2 on Linux so there is the possibility that something else is going on in the Google Mock headers when compiling on Windows.
Answering for anyone still facing the same issue:
The source of this issue might be in your CMakeLists file.
Set your compiler flags to -std=gnu++ instead of -std=c++
One way to do it would be to include
set(CMAKE_CXX_FLAGS "-std=gnu++0x")
to your CMakeLists file.

G++ 4.4 compile error, lower versions works

I have my program written in C++ and it is can be successfully compiled on Ubuntu 9.04 with g++ 4.3.4 and Solaris OS with g++ 3.4.3. Now I have upgraded my Ubuntu to version 9.10 and g++ to version 4.4.1. Now compiler invokes the error in STL.
/usr/include/c++/4.4/bits/stl_deque.h: In member function ‘void std::deque<_Tp, _Alloc>::swap(std::deque<_Tp, _Alloc>&)’:
In file included from /usr/include/c++/4.4/deque:65,
/usr/include/c++/4.4/bits/stl_deque.h:1404: error: ‘swap’ is not a member of ‘std’
/usr/include/c++/4.4/bits/stl_deque.h:1405: error: ‘swap’ is not a member of ‘std’
/usr/include/c++/4.4/bits/stl_deque.h:1406: error: ‘swap’ is not a member of ‘std’
/usr/include/c++/4.4/bits/stl_deque.h:1407: error: ‘swap’ is not a member of ‘std’
I don't know how to fix it and if is possible that stl contains a bug. Can you help me, please?
Thanks a lot for all advices.
#include <algorithm>
In older versions of GCC, if you included any standard library header, that header would usually include many others. As mentioned by others, in your case <algorithm> got included this way.
This behavior isn't required by the standard. Many other implementations of the standard library don't exhibit this behavior, or to a lesser degree. It was just a design decision made by the GCC developers long ago. It seems they are now reducing this behavior, bringing it more in line with other implementations. This gives you more control over what gets included and what doesn't. Old code will break, but it's easily fixed by including the missing headers.
A post on an Apple forum suggests
#include <algorithm>