Problem in including STL header files - c++

I have created Dialog Based application in MFC (VS 2008).When I do "#include" in Dlg.cpp it showing following error.
Is Some Component is missing in the VS 2008 Installation
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(43) :
error C2665: 'operator new' : none of the 5 overloads could convert all the argument types
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(85): could be 'void *operator new(size_t,const std::nothrow_t &) throw()'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(93): or 'void *operator new(size_t,void *)'
1> while trying to match the argument list '(const char [70], int)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(145) : see reference to function template instantiation '_Ty *std::_Allocate<char>(size_t,_Ty *)' being compiled
1> with
1> [
1> _Ty=char
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(144) : while compiling class template member function 'char *std::allocator<_Ty>::allocate(std::allocator<_Ty>::size_type)'
1> with
1> [
1> _Ty=char
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xstring(2216) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=char
1> ]
1>Build log was saved at "file://c:\Users\Public\Documents\Proj\STL1\STL1\Debug\BuildLog.htm"
1>STL1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any STL includes in your MFC project should be included prior to the definition of DEBUG_NEW. This was a problem in the past (no longer seems to be, as I cannot reproduce it in VS 2010).
// myfile.cpp
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// This will cause the error
#include <vector>
Whereas
// myfile.cpp
// will work OK
#include <vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
DEBUG_NEW is a microsoft specific extension that helps to find memory leaks in debug versions of the application. It can be very useful in certain cases.
It's defined in afx.h as:
void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#define DEBUG_NEW new(THIS_FILE, __LINE__)`
It's helps to provide tracking of memory allocated and when a leak is detected will give you the file and line number where the allocation took place.

Related

Compiler Error occurs (Intel Parallel Studio 2020 19.1 with Visual Studio Community 2019)

I have a very simple example
#include
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
If I compile this with Visual Studio Compiler on Visual Studio Community 2019, then it works as expected.
However, when I change the compiler to Intel C++, installed with Intel Parallel Studio 2020(19.1), it returns an error
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>Source.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(92): error : expected an identifier
1> !_Is_implicitly_default_constructible<_Uty1>::value || !_Is_implicitly_default_constructible<_Uty2>::value)
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(91): error : not a valid member class or function template declaration
1> constexpr explicit(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(91): error : "explicit" is not allowed
1> constexpr explicit(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(93): error : expected a ";"
1> pair() noexcept(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : expected an identifier
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : not a valid member class or function template declaration
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : "explicit" is not allowed
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(177): error : expected a ";"
1> pair(const pair<_Other1, _Other2>& _Right) noexcept(is_nothrow_constructible_v<_Ty1, const _Other1&>&&
1> ^
1>
1>compilation aborted for Source.cpp (code 2)
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If I comment out the #include and std::cout ~~, which is basically an empty program, then it compiles successfully and runs without error.
My system is
OS: 64bit Windows 10 Enterprise

Compiler Error (Intel Parallel Studio 2019 with Visual Studio Community 2019)

I have a very simple example
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
If I compile this with Visual Studio Compiler on Visual Studio Community 2019, then it works as expected.
However, when I change the compiler to Intel C++, installed with Intel Parallel Studio 2019, it returns an error
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>Source.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(92): error : expected an identifier
1> !_Is_implicitly_default_constructible<_Uty1>::value || !_Is_implicitly_default_constructible<_Uty2>::value)
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(91): error : not a valid member class or function template declaration
1> constexpr explicit(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(91): error : "explicit" is not allowed
1> constexpr explicit(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(93): error : expected a ";"
1> pair() noexcept(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : expected an identifier
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : not a valid member class or function template declaration
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : "explicit" is not allowed
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(177): error : expected a ";"
1> pair(const pair<_Other1, _Other2>& _Right) noexcept(is_nothrow_constructible_v<_Ty1, const _Other1&>&&
1> ^
1>
1>compilation aborted for Source.cpp (code 2)
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If I comment out the #include <iostream> and std::cout ~~, which is basically an empty program, then it compiles successfully and runs without error.
My system is
OS: 64bit Windows 10 Enterprise
CPU: AMD Ryzen Threadripper 3970X
I had a similar compiling erro:
c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\concepts(47): error : expected ';', near '{'
If I Disable the "bullseye coverage 8.9.44" (compatible til VS 2015) my prog compile with success.

Conversion Error from 'unsigned __int64' to 'unsigned __int64 *' - Pybind11

After downloading this https://github.com/pybind/pybind11/archive/v2.2.3.zip
and creating a simple cpp file:
#include <pybind11/pybind11.h>
int add(int i, int j) { return i + j; }
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function which adds two numbers");
}
with
I get this error
Error C2446 '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *' in c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector line 2326
Would anybody know what this could be referring to, and possibly how to fix it?
As requested, here the full error log:
1>------ Rebuild All started: Project: Test_CreatePythonBindings, Configuration: Debug x64 ------
1>example.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): error C2446: '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2325): note: while compiling class template member function 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2545): note: see reference to function template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2490): note: see reference to class template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3094): note: see reference to class template instantiation 'std::_Vb_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3093): note: while compiling class template member function 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)'
1> with
1> [
1> _Ty=bool
1> ]
1>c:\pybind11-2.2.3\include\pybind11\pybind11.h(513): note: see reference to function template instantiation 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)' being compiled
1> with
1> [
1> _Ty=bool
1> ]
1>c:\pybind11-2.2.3\include\pybind11\cast.h(1806): note: see reference to class template instantiation 'std::vector<bool,std::allocator<_Ty>>' being compiled
1> with
1> [
1> _Ty=bool
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence
1>Done building project "Test_CreatePythonBindings.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
It appears to be a VS 2017 issue related to
std::vector<bool>
Separate question asked here:
Pushback on vector<bool> fails - VS 2017

With VC 15.4.0, std::function assignment produces C2679 (compiled with 15.3.5)

The following code compiles just fine with VC 15.3.5:
#include <Windows.h>
#include <string>
#include <memory>
#include <optional>
#include <functional>
class TypeDictionary;
class IStructureField {};
using FieldFactory = std::function<std::unique_ptr<IStructureField>(TypeDictionary& dict, LPCSTR szName, std::optional<ULONG> ulOffset, std::optional<std::string> strFieldType, std::optional<ULONG> ulFieldSize)>;
int main()
{
FieldFactory ff;
ff = [](TypeDictionary& dict, LPCSTR szName, std::optional<ULONG> ulOffset, std::optional<std::string> szFieldType, std::optional<ULONG> ulFieldSize) -> std::unique_ptr<IStructureField> {
return std::unique_ptr<IStructureField>();
};
return 0;
}
It produces the following error message with 15.4.0:
1>f:\projects\fullpath\fullpath\fullpath.cpp(22): error C2679: binary '=': no operator found which takes a right-hand operand of type 'main::<lambda_36489dce1cc59e5a8de4329a29806b5a>' (or there is no acceptable conversion)
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.11.25503\include\functional(656): note: could be 'std::function<std::unique_ptr<IStructureField,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)> &std::function<std::unique_ptr<_Ty,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)>::operator =(std::nullptr_t) noexcept'
1> with
1> [
1> _Ty=IStructureField
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.11.25503\include\functional(629): note: or 'std::function<std::unique_ptr<IStructureField,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)> &std::function<std::unique_ptr<_Ty,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)>::operator =(std::function<std::unique_ptr<_Ty,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)> &&)'
1> with
1> [
1> _Ty=IStructureField
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.11.25503\include\functional(612): note: or 'std::function<std::unique_ptr<IStructureField,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)> &std::function<std::unique_ptr<_Ty,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)>::operator =(const std::function<std::unique_ptr<_Ty,std::default_delete<_Ty>> (TypeDictionary &,LPCSTR,std::optional<ULONG>,std::optional<std::string>,std::optional<ULONG>)> &)'
1> with
1> [
1> _Ty=IStructureField
1> ]
1>f:\projects\fullpath\fullpath\fullpath.cpp(22): note: while trying to match the argument list '(FieldFactory, main::<lambda_36489dce1cc59e5a8de4329a29806b5a>)'
1>Done building project "FullPath.vcxproj" -- FAILED.
As I saw on cppcon (Stephan's talk), a lot of work has been done on <functional>... Could this be related? Any mistake I made?
Workarounds would be fine too.
Edit1: Added the two include files to help understand the issue is not there: Same error...
Edit2: After I repaired my VS installation, the code just compiled. However, the original code did not. I had bumped in https://developercommunity.visualstudio.com/content/problem/74313/compiler-error-in-xsmf-control-with-stdoptional-pa.html before and attempted the workaround (which exposed the issue I faced). Without the workaround, the code compiles (but hits the __this issue again...).

returning a boost ublas matrix by value working only in release config for vs2012

I'm using visual studio 2012 and I isolated a problem in my code to this, but I can't solve it. When running it in release mode it works perfect, but I get an error if I run it in debug.
The code is:
#include "stdafx.h"
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::matrix<double> BMT;
BMT fun()
{
BMT mym;
mym.resize(3,3);
for(int i = 0; i<9;++i) mym(i/3,i%3)=i;
std::cout << mym << std::endl;
return mym;
}
int main(int argc, char* argv[])
{
fun();
//closing message
std::cout<<std::endl<<"press enter to exit."<<std::endl;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
and the error in debug is the following:
1>------ Build started: Project: myproject, Configuration: Debug x64 ------
1> myapp.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory(348): error C4996: 'std::_Uninitialized_copy0': 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'
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory(333) : see declaration of 'std::_Uninitialized_copy0'
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/storage.hpp(94) : see reference to function template instantiation '_FwdIt std::uninitialized_copy<const double*,double*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=double *,
1> _InIt=const double *
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/storage.hpp(89) : while compiling class template member function 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)'
1> with
1> [
1> T=double
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/matrix.hpp(160) : see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)' being compiled
1> with
1> [
1> T=double
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/matrix.hpp(100) : see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<T>' being compiled
1> with
1> [
1> T=double
1> ]
1> junkApp1.cpp(10) : see reference to class template instantiation 'boost::numeric::ublas::matrix<T>' being compiled
1> with
1> [
1> T=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Do you know what can the problem be?
I was having a similar issue using ublas.
I am not sure what the cause might be but I suppose it's got to do with ublas' copy on write / copy on demand optimizations. Would it be an option to just use the define -D_SCL_SECURE_NO_WARNINGS and be done with it? I have that set globally as I consider 90% of those warnings OS specifc BS anyway.
The problem is that you are compiling with warnings treated as errors.
EDIT: Microsoft has decided that certain parts of C++ (and C) are deprecated, and the compiler reports use of those parts as errors unless _SCL_SECURE_NO_WARNINGS (respectively _CRT_SECURE_NO_WARNINGS) is defined.