C2143/C2518 when trying to compile project using boost.multiprecision - c++

I've been having problems trying to get boost.multiprecision to work in my VC2017 project, and I tried to make the simplest project possible as a proof of concept:
#include<boost/multiprecision/cpp_int.hpp>
int main() {
boost::multiprecision::cpp_int val{ 5 };
val *= 5;
val *= 5;
return val.convert_to<int>();
}
Unfortunately, this code does not compile, with the following errors:
1>------ Build started: Project: Multiprecision Test, Configuration: Debug x64 ------
1>Multi Main.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(59): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(467): note: see reference to class template instantiation 'boost::numeric::convdetail::trivial_converter_impl<Traits>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(454): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(497): note: see reference to class template instantiation 'boost::numeric::convdetail::rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(475): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(526): note: see reference to class template instantiation 'boost::numeric::convdetail::non_rounding_converter<Traits,RangeChecker,RawConverter>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(505): error C2518: keyword 'typename' illegal in base class list; ignored
1>Done building project "Multiprecision Test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
These are the exact same errors I'm getting in the more complex project that originally used boost.multiprecision. I had no problems getting this code to compile in Visual Studio 2015. Does anyone know what's wrong, and what I need to do to fix it?
EDIT:
A project using boost.asio compiles with no issues:
#include<boost/asio.hpp>
#include<iostream>
int main() {
boost::asio::io_service service;
for (int i = 0; i < 10; i++) {
service.post([i] {
std::cout << i << std::endl;
});
}
service.run();
system("pause");
return 0;
}

The problem is caused by the fact that some templates in boost::multiprecision use std::unary_function, which has been deprecated since C++11 and was removed from the standard for C++17.
The standard library implementation in MSVC 2015 introduced guards like #if _HAS_AUTO_PTR_ETC around such deprecated definitions. They are set to 1 by default under the new switch /std:c++14 (the default) and set to 0 by default under /std:c++latest (the new compiler switches are available since 2015 Update 3).
So, until boost removes the dependencies on std::unary_function, you have to either not use /std:c++latest (I've always been using it since it came out) or #define _HAS_AUTO_PTR_ETC 1 before including (directly or indirectly) any standard library headers. So, either set it with compiler options or in some PCH that is the first that gets included in all translation units or something like that.
A thorough description of these settings, including other guards that control other deprecated or removed features, can be found in this blog post by Stephan T. Lavavej. The Visual C++ change history 2003 - 2015 seems to be the official list of breaking changes in MSVC, but unfortunately it doesn't cover all these details. In general, scanning the Visual C++ Team Blog for posts from Stephan will give you the best info on these things.

Related

fatal error C1001: TwoPhase Lookup failed on Template Function

I use the current Release of the Poco Library (1.12.0)
With that release i was unable to build the following Program with Visual Studio 2019 and 2022 (Platformtoolset vs142 and vs143):
#include <iostream>
#include <Poco/Any.h>
int main() {
Poco::Any any_type;
std::cout << "Test\n";
}
If i run the Compiler i got the following Error:
C:\Users\User\Documents\Unterlagen\Projekte\programming\cpp\_libraries\poco\Foundation\include\Poco\Any.h(124,1): fatal error C1001: Internal compiler error.
1>(compiler file 'msc1.cpp', line 1693)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>If possible please provide a repro here: https://developercommunity.visualstudio.com
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>C:\Users\User\Documents\Unterlagen\Projekte\programming\cpp\_libraries\poco\Foundation\include\Poco\Any.h(210): message : see reference to class template instantiation 'Poco::Placeholder<PlaceholderT,SizeV>' being compiled
1>INTERNAL COMPILER ERROR in 'C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\CL.exe'
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>Done building project "Project1.vcxproj" -- FAILED.
I found out that the error occured because of the /Zc:twoPhase Option which is set by the /permissive- Option which is by default set. If i add /Zc:twoPhase- to disable the Two-Phase Lookup the code compiles successfully.
But i want to fix this issue inside the Any.h.
This is the Code which is mentioned in the Error:
template<typename T, typename V,
typename std::enable_if<TypeSizeGT<T, Placeholder::Size::value>::value>::type* = nullptr>
PlaceholderT* assign(const V& value)
==> {
erase();
pHolder = new T(value);
setLocal(false);
return pHolder;
}
The Arrow indicates the Line the Compiler mentioned.
I guess i need to add something to the Function Decleration but i'm not so deep inside templates.
Does anybody knows what i had to add so that MSVC is not complaining anymore??

attempting to reference a deleted function for atomic c++

I have a piece of code that use to work for Visual Studio 2013. Now that I'm trying to build the same code in Visual Studio 2017 it complains. Here is the code I'm trying to do.
#include <array>
#include <atomic>
int main()
{
using TrdRobotStateArray = std::array<std::atomic<double>, 6>;
TrdRobotStateArray mCurrentPose = { 0.3 };
printf("%0.3f", mCurrentPose[0]);
return 0;
}
With this, I get this error:
error C2280: 'std::atomic<double>::atomic(const std::atomic<double> &)': attempting to reference a deleted function
I didn't write this code, and I'm trying to read into atomic variables. But I'm still not quite sure what is going on with the error. An explanation about atomics would be greatly appreciated. Thanks!
update:
Here are all the errors and warnings that came with this code. So it would help others in the future.
1>AtomicTest.cpp
1>AtomicTest.cpp(13): error C4839: non-standard use of class
'std::atomic<double>' as an argument to a variadic function
1>AtomicTest.cpp(13): note: the constructor and destructor will not be
called; a bitwise copy of the class will be passed as the argument
1>AtomicTest.cpp(11): note: see declaration of 'std::atomic<double>'
1>AtomicTest.cpp(13): error C2280: 'std::atomic<double>::atomic(const
std::atomic<double> &)': attempting to reference a deleted function
1>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\atomic(689):
note: see declaration of 'std::atomic<double>::atomic'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\atomic(689):
note: 'std::atomic<double>::atomic(const std::atomic<double> &)': function
was explicitly deleted
1>AtomicTest.cpp(13): warning C4477: 'printf' : format string '%0.3f'
requires an argument of type 'double', but variadic argument 1 has type
'std::atomic<double>'
1>Done building project "AtomicTest.vcxproj" -- FAILED.
You have to load the value explicitely in order to compile it:
printf("%0.3d", mCurrentPose[0].load());
Otherwise, it will try to copy the atomic variable itself for printf() which clearly is not the intent.
Atomic variables are not CopyConstructible.
This is a requirement of the C++ standard, so VisualStudio 2017 is correct.

C++, curious compiler error when implementing a function `int next(std::string param)`

I've been badly bitten by the following code, on which I wasted many hours of precious time.
#include<string>
int next(std::string param){
return 0;
}
void foo(){
next(std::string{ "abc" });
}
This produces the following compiler error (on Visual Studio 2013):
1>------ Build started: Project: sandbox, Configuration: Debug Win32 ------
1> test.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2039: 'iterator_category' : is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1> c:\users\ray\dropbox\programming\c++\sandbox\test.cpp(8) : see reference to class template instantiation 'std::iterator_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>' being compiled
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2146: syntax error : missing ';' before identifier 'iterator_category'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2602: 'std::iterator_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>::iterator_category' is not a member of a base class of 'std::iterator_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371) : see declaration of 'std::iterator_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>::iterator_category'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2868: 'std::iterator_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>::iterator_category' : illegal syntax for using-declaration; expected qualified-name
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I found out later that if I change my function name from next() to something else, all is fine. To me, this indicates that there is a name conflict, specifically of the name next. I find this strange because I didn't use anything like using namespace std. As far as I know, next is not a built-in C++ keyword (is it?). I looked up next here, but it's std::next and as I said I didn't using namespace std. So how did this conflict happen? How do I prevent similar things in the future? What other names might cause a conflict like this?
There are several things going on here, interacting in subtle ways.
Firstly, an unqualified call to next with an argument of type std::string means that as well as your own next function, the standard function template std::next is found by Argument-dependent lookup (ADL).
After name lookup has found your ::next and the standard library's std::next it performs overload resolution to see which one is a better match for the arguments you called it with.
The definition of std::next looks like:
template <class ForwardIterator>
ForwardIterator next(ForwardIterator x,
typename std::iterator_traits<ForwardIterator>::difference_type n = 1);
This means that when the compiler performs overload resolution it substitutes the type std::string into std::iterator_traits<std::string>.
Prior to C++14 iterator_traits is not SFINAE-friendly which means that it is invalid to instantiate it with a type that is not an iterator. std::string is not an iterator, so it's invalid. The SFINAE rule does not apply here, because the error is not in the immediate context, and so using iterator_traits<T>::difference_type for any non-iterator T will produce a hard error, not a substitution failure.
Your code should work correctly in C++14, or using a different standard library implementation that already provides a SFINAE-friendly iterator_traits, such as GCC's library. I believe Microsoft will also provide a SFINAE-friendly iterator_traits for the next major release of Visual Studio.
To make your code work now you can qualify the call to next so ADL is not performed:
::next(std::string{ "abc" });
This says to call the next in the global namespace, rather than any other next that might be found by unqualified name lookup.
(Updated per Jonathan's comments)
There are two views here, the C++11 and the C++14 view. Back in 2013, C++11's std::next was not properly defined. It is supposed to apply to iterators, but due to what looks like an oversight it will cause hard failures when you pass it a non-iterator. I believe the intention was that SFINAE should have prevented this; std::iterator_traits<X> should cause substitution failures.
In C++14, this problem is solved. The definition of std::next hasn't changed, but it's second argument (std::iterator_traits<>) is now properly empty for non-iterators. This eliminates std::next from the overload set for non-iterators.
The relevant declaration (taken from VS2013) is
template<class _FwdIt> inline
_FwdIt next(_FwdIt _First,
typename iterator_traits<_FwdIt>::difference_type _Off = 1)
This function should be added to the overload set if it can be instantiated for the given arguments.
The function is found via Argument Dependent Lookup and Microsoft's header structure. They put std::next in <xutility> which is shared between <string> and <iterator>
Note: _FwdIt and _Off are part of the implementation namespace. Don't use leading underscores yourself.
Actually std::next() is a function defined in <iterator> which returns the next iterator passed to std::next(). Your code is running on my computer with gcc-4.9.2. More : http://en.cppreference.com/w/cpp/iterator/next
The code I used:
#include<string>
#include <iostream>
int next(std::string param){
std::cout<<param<<std::endl;
return 0;
}
void foo(){
next(std::string{ "abc" });
}
int main()
{
foo();
return 0;
}
Also on ideone : http://ideone.com/QVxbO4
The compiler found standard function std::next due to the so-called Argument Dependent Lookup because the argument used in the call - std::string - is declared in namespace std.

Compile error that goes away with comment/debug/uncomment/debug on a single line

Below is a header file in my program.
I was getting a compile error, saying that I was missing a semi-colon before partyPack.
There is none missing. There were two other errors but I don't recall what they were.
What's really confusing to me is I commented out Pack partyPack; compiled (failed because it was referenced in the .cpp), and when I uncommented and tried again, it compiled and ran.
What could cause this behavior?
#ifndef PARTY_INTERFACE
#define PARTY_INTERFACE
#include "utility.h"
#include "Pack.h"
#include "Shop.h"
#include "Assets.h"
struct member
{...};
class Party
{
private:
const static int TEAMSIZE = 4;
member team[TEAMSIZE];
Pack partyPack;
const Inventory* itemList;
public:
Party(const Inventory* inputList);
void newTeam();
bool load();
bool save();
void findItem();
const void showParty();
const void showInventory();
void addToInventory();
~Party(void);
};
#endif
Update 1
I have been able to replicate the error ...
Below is a link to a github repo containing the program's files for reference, feel free to download and debug, etc. The last commit compiled for me in VC++ 2010. I've commented out the portions which require windows.h, it should compile universally ... I hope.
https://github.com/dsball/RPGShop/tree/master/RPGShop
Update 2
I've isolated the problem to being any time something is changed in one of the header files included in Party.h or in Party.h itself. The simple act of typing int a; and immediately deleting it(with nothing between those two steps) causes the bug. The errors follow:
Error 1 error C2146: syntax error : missing ';' before identifier 'partyPack' party.h 30
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int party.h 30
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int party.h 30
Then I comment line 30 in Pack.h //Pack partyPack, compile/start debugging (which fails), uncomment the same line and try again, it runs just fine.
Update 3
I have replaced Pack with Backpack after learning there is a Pack() pragma, but the issue remains the same.
As was mentioned by others, it does seem like there's something interfering with the definition of Party, but I can't find what it is.
(In later versions, pack has been renamed to backpack. This answer uses 'backpack' in place of 'pack')
When compiling under G++ (after appropriate modifications to remove Windows-specific code), I get this error:
$ g++ -std=c++0x *.cpp
In file included from Shop.h:6:0,
from Backpack.h:5,
from Backpack.cpp:1:
Party.h:30:2: error: ‘Backpack’ does not name a type
It looks like the issue is that Backpack.h is including party.h, but at line 5 in Backpack.h, the Backpack class has not yet been defined. Party.h includes Backpack.h in its line 5, but since Backpack.h has already been included, the #ifndef statement prevents Backpack.h from being included a second time (which would otherwise create an infinite loop of #include statements).
In summary, it looks like this issue is due to circular dependencies. I would find a way to break the dependency cycle between Backpack.h and Party.h.
In terms of why this is flaky, I'm guessing that VC caches fully-loaded headers as an optimization. If Backpack.h had been fully-loaded, then this error wouldn't occur.
Most likely Pack is undefined. But there's a header present that likely defines it, so...is it defined in another namespace? ( you might need to use explicit namespace locator like pack_namespace::Pack partyPack; )

c++ build error

I am trying to integrate wwise into a test project. I have a project on windows 7 using ms visual studio 2010 and this is the error I get after I try and add a necassary cpp to the project. i dont get this build error on my machine at home with the same set up, what does it mean?
------ Build started: Project: wwise test, Configuration: Debug Win32 ------
AkFilePackageLUT.cpp
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.h(204): error C2065: 'NULL' : undeclared identifier
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.cpp(117) : see reference to function template instantiation 'const CAkFilePackageLUT::AkFileEntry<T_FILEID> *CAkFilePackageLUT::LookupFile<AkFileID>(T_FILEID,const CAkFilePackageLUT::FileLUT<T_FILEID> *,bool)' being compiled
with
[
T_FILEID=AkFileID
]
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.h(204): error C2065: 'NULL' : undeclared identifier
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.cpp(140) : see reference to function template instantiation 'const CAkFilePackageLUT::AkFileEntry<T_FILEID> *CAkFilePackageLUT::LookupFile<AkUInt64>(T_FILEID,const CAkFilePackageLUT::FileLUT<T_FILEID> *,bool)' being compiled
with
[
T_FILEID=AkUInt64
]
To me it looks on the first glance like you did not specify a template parameter .
Other possible causes:
You are compiling with a debug version of the C runtime, declaring a
Standard C++ Library iterator variable in a for loop, and then
trying to use that iterator variable outside the scope of the for
loop. Compiling Standard C++ Library code with a debug version of
the C runtime implies /Zc:forScope. See Debug Iterator Support for
more information.
You may be calling a function in an SDK header file that is
currently not supported in your build environment.
Omitting necessary include files, especially if you define
VC_EXTRALEAN, WIN32_LEAN_AND_MEAN, or WIN32_EXTRA_LEAN. These
symbols exclude some header files from windows.h and afxv_w32.h to
speed compiles. (Look in windows.h and afxv_w32.h for an up-to-date
description of what's excluded.)
Identifier name is misspelled.
Identifier uses the wrong uppercase and lowercase letters.
Missing closing quote after a string constant.
Improper namespace scope. To resolve ANSI C++ Standard Library
functions and operators, for example, you must specify the std
namespace with the using directive. The following example fails to
compile because the using directive is commented out and cout is
defined in the std namespace
This error message is saying the following:
in <path...>\akfilepackagelut.h there is a definition of a function template. In fact, it is a templated method of a class. Inside that definition, on line 204, the name NULL is used. NULL is defined in header <cstddef> of the C standard library, and normally you can include that definition by including one of a lot of C/C++ headers, because most of them somehow include <cstddef>. However, akfilepackagelut.h seems to include only headers that in the VS2012 installation you are using do not include that definition, so the compiler does not know what NULL means.
The whole rest of the error message is just template error gibberish, telling you that that function template we are talking about has been instantiated twice somewhere in AkFilePackageLUT.cpp, telling you the exact locations and the template parameters and so on.
What can you do?
Well, if you can not modify the source as you say (Why? You have the source) you can't do anything but perhaps file a bug for the project. If you can modify it would be best to #include <cstddef> in akfilepackagelut.h.