Locating error in source which is boost related [duplicate] - c++

This question already has answers here:
C++ Boost: what's the cause of this warning?
(6 answers)
Closed 2 years ago.
I'm porting an old project from Boost 1.48 to Boost 1.61. The project is compiled using MSVC 2013. There are several reported errors during build which I think are boost related but unfortunately the bug reports are not very helpful at all.
3> entry.cpp
4>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2715): error C2220: warning treated as error - no 'object' file generated
4>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2715): warning C4996: 'std::_Fill_n': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
4> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2701) : see declaration of 'std::_Fill_n'
4> c:\boost\boost_1_61_0\boost\random\detail\polynomial.hpp(114) : see reference to function template instantiation '_OutIt std::fill_n<boost::random::detail::polynomial_ops::digit_t*,size_t,boost::random::detail::polynomial_ops::digit_t>(_OutIt,_Diff,const _Ty &)' being compiled
4> with
4> [
4> _OutIt=boost::random::detail::polynomial_ops::digit_t *
4> , _Diff=size_t
4> , _Ty=boost::random::detail::polynomial_ops::digit_t
4> ]
I cannot see anything in the above that helps me identify where the problem is, there are no line numbers and the snippet of code is not from the compiled file.

#Eljay, does it have a human readable text option I could locate in the IDE? – SPlatten 43 mins ago
The thing you posted IS human readable text. It actually describes a warning with a reference to documentation. ¯\(ツ)/¯ Maybe you can just tell the compiler you don't want to receive warnings
In addition, you can use the keywords to google additional information:
C++ Boost: what's the cause of this warning?
Many libraries in addition already have a warning-suppression header (look for e.g. boost/iostreams/detail/config/disable_warnings.hpp or boost/random/detail/disable_warnings.hpp). The fact that known benign warnings "slip through" might indicate that the library needs to update their suppressions, OR you might need to upgrade your boost version.

Related

Is there any way to force visual studio to show me location of an error in *my* code, instead of pointing to the standard library?

I have a small piece of code that does not compile
Visual Studio shows me this error and points to xhash:
Error C2064 term does not evaluate to a function taking 1 arguments C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash 114
I know that error is somewhere in my code, probably related to unordered map, so template does not resolve. I'm wondering if there's a way to see which part of my code causes compilation error
The full build output will have many more lines, in the form ".. Instantiated from here...". Typically the last of these lines will point to your faulty code, possibly more if you wrote a template yourself.

Unable to compile example boost::multiprecision with intel compiler on windows

I am using VS 2017 Community edition, Intel Compiler 17.00 update 6 and and boost 1.66, trying to learn my way around boost::multiprecision::float128. Literally taking the example code from here and putting it in a new project for VS.
Compiling gives multiple errors, in roughly two categories/files:
In float128.hpp:
three errors of "error : identifier "xxx" is undefined" for fmaq, remquoq and remainderq. Indeed I am not able to find definitions for them - a missing include?
the global scope has no "signbitq" - this again looks like missing definition (i.e. the same as above)
For GCC the above functions are found within quadmath.h, however, the boost header doesn't seem to include it when using ICC (i.e BOOST_MP_USE_QUAD is set).
In C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\include\xutility: an explicit template argument list is not allowed on this declaration. There are three counts
I assume that i need to remove something that has been put in by default from the VS, but I am at a loss what exactly.
Thank you for your help
EDIT: Errors #2 above are actually not against boost at all (should I move this to a separate question?).
The following code copied from here! is not being compiled in my setup:
#include <iostream>
#include <string>
int main() {
std::string str("Test string");
for (std::string::iterator it = str.begin(); it != str.end(); ++it)
std::cout << *it;
std::cout << '\n';
return 0;
}
The exact error (one of them) is:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\include\xutility(680): error : an explicit template argument list is not allowed on this declaration
1> _INLINE_VAR constexpr bool _Is_iterator_v<_Ty, void_t<_Iter_cat_t<_Ty>>> = true;
1> ^
1> detected during:
1> instantiation of "const bool std::_Is_iterator_v [with _Ty=char *, <unnamed>=void]" at line 520 of "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\include\string"
1> instantiation of "std::basic_string<_Elem, std::char_traits<_Elem>, std::allocator<_Elem>> std::_Integral_to_string<_Elem,_Ty>(_Ty) [with _Elem=char, _Ty=int]" at line 554 of "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\include\string"
I found this which indicates that there could be a problem with the particular versions used (ICC- 17.0 Up6 and VS 15.6), however i cannot really move to new intel compiler and i cannot test VS 15.4
I would like to write down how I managed to deal with error #2 from the original question, as it might be useful to someone.
Just as a reminder, the second errors I was seeing were in xutility. With the help of everyone that provided suggestions, it turned out that icc was in fact failing on very simple code - the following is enough to "break" it
int main() {
std::string str("Test string");
}
I have posted the question to intel's forums, however so far I have not received answers (for the 17.0 version of the compiler). Link here if anyone is interested.
That said, I came upon this blog post from the VC++ team, showing that the base toolset shown as v141 in VC2017 actually has had several minor revisions. It is possible to change the version of the MSVC toolchain but this needs to happen via editing of project files (rather than UI parameter changes).
My testing shows that version 14.11 (which is part of VS2017 15.3 and 15.4) works for Intel 17.0 while versions 14.12 and 14.13 (the last one is the current default for VS2017 15.6.4) do not. This has been done for Update 6 of the compiler. So in order to use the intel compiler on windows with visual studio, one needs to use particular MSVC toolchain versions.
Side note: I also installed icc version 18.0 update 1 for testing -- it too was giving compiler errors (and not just for me this time). The reason there though can be linked to some internal issue for icc, per this forum post. I can confirm that removing the compiler option /permissive- from the compiler fixes the errors irrespective of the base toolchain. Using v14.11 as base toolchain also fixes this particular problem for me with or without the option. /permissive- is a new option for icc (it is not part of 17.0).
The above solves more or less the second part of my problem with the icc. The rest of the question (boost's float128) though still remains. I will add more if i hear from boost's guys.
EDIT: the errors coming from boost turned out to be an issue there -- it was fixed by the maintainers in development branch, so this is resolved as well.
For Error #1, I got the same thing. However, after commenting the code blocks in boost float128.hpp where those four functions invoked, the float128 example code can be compiled with success. The side effect is unknown. I'm looking forward a revision on boost::multiprecision::float128.

Why visual studio needs <string> to compile, but codeblocks doesnt?

Basically, the program is compiling on codeblocks, but not on visual studio 2015 unless I add
#include <string>
to one of the files, then I get about errors from the first line of the code
1>------ Build started: Project: ConsoleApplication2, Configuration: Release Win32 ------
1> pytanie.cpp
1>pytanie.cpp(25): error C3861: 'getline': identifier not found
1>pytanie.cpp(42): error C2679: binary '<<': no operator found which takes a
right-hand operand of type 'std::string' (or there is no acceptable
conversion)
and about 200 lines of this stuff
'std::basic_ostream<char,std::char_traits<char>>
&std::basic_ostream<char,std::char_traits<char>>::operator <<(const void *)'
So the question is, why codeblocks can compile and run this program, but visual studio needs
#include <string>
I found out - thanks to this forum - that using getline and << operator requires including the 'include string' line, but why can codeblocks work without it, or why visual studio 2015 CAN'T?
edit: yes, codeblock is using GNU GCC compiler and VS2015 is using default one
Any standard header file is allowed, but not required, to include any other.
So on one compiler one of the headers you're including does include <string>, and on the other compiler none of them do.
This is generally tricky (by which I mean it's extremely hard to get right, even for experts), but for portability I'm afraid you need to know which headers include the declarations you use, and make sure you include all of them.

std::forward compiling error VS2010

I am getting a weird error that I can't understand(since it's from a native file of VS) from file utility(it's located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\), it is being compiled in my project with Visual C++ 10.0.
'std::forward' : cannot convert parameter 1 from '' to '&'
template<class _Other1, class _Other2>
pair(_Other1&& _Val1, _Other2&& _Val2)
: _Mybase(_STD forward<_Other1>(_Val1), _STD forward<_Other2>(_Val2))
{ // construct from moved values
}
Can anyone explain this error? It seems to me very strange, but I'm totally new to C++ and I don't understand how to fix it.
The error seems to be here:
std::map<std::string, DWORD>::value_type("SOME_STRING", 8192);
And the compilation reports this:
see reference to function template instantiation
'std::pair<_Ty1,_Ty2>::pair<const char(&)[12],>(_Other1,_Other2 &&)'
being compiled with
[
_Ty1=const std::string,
_Ty2=DWORD,
_Other1=const char (&)[12],
_Other2=
]
It seems the compiler is incapable of coping with the string literal passed in. I don't know whether it's a bug in the standard library implementation VS2010 uses, or whether it hits an edge case in the standard (and is actually supposed to fail), but either way, you can solve it by explicitly creating a std::string from the literal:
std::map<std::string, DWORD>::value_type(std::string("SOME_STRING"), 8192);

How can I test the portability of a C++ codebase developed and managed in Visual Studio 2010?

I have a very large and very old C++ project currently maintained in Visual Studio 2010. One member of our team has just tested the bumpiness of the upgrade path to VS 2012, and found we were being affected by this, through our use of Microsoft's non-standard extensions to the language.
Is there any tool we can run over our codebase that will tell us how many other non-standard extensions we're using, so we can eliminate them before they cause us any more problems?
Specify the compiler switch /Za which disables extensions.
For example, the following code:
#include <string>
void f(std::string&) {}
int main()
{
f(std::string("hello"));
}
Compiles (with warning) when /Za is not specified but fails to compile when /Za is specified with the following error:
main.cpp(7) : error C2664: 'f' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'std::string &'
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]
A non-const reference may only be bound to an lvalue