Does this class satisfy the Allocator requirement? - c++

I made a custom allocator, but my code didn't compile on msvc and I'm not sure if my implementation satisfies the Allocator requirement (disregarding actual behavior of function implementations here). Here is a minimal example that reproduces the error on Visual Studio (16.11 P1 and 16.10):
#include <memory>
#include <vector>
template <typename T>
class Allocator
{
public:
using value_type = T;
[[nodiscard]]
T* allocate(std::size_t n)
{
return nullptr;
}
void deallocate(T* x, std::size_t n)
{
}
constexpr bool operator==(const Allocator& other) const noexcept
{
return true;
}
constexpr bool operator!=(const Allocator& other) const noexcept
{
return !(*this == other);
}
};
int main()
{
using Alloc = Allocator<int>;
using Vec = std::vector<int, Alloc>;
auto vec = Vec();
}
Godbolt isn't complaining for any major compiler but their msvc version is a little behind I think.
To me this looks like a compiler bug in msvc but I want to make sure before I open a ticket.
This is the compiler output:
Build started...
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(714,27): error C2440: 'static_cast': cannot convert from 'Allocator<int>' to 'Allocator<_Newfirst>'
1> with
1> [
1> _Newfirst=std::_Container_proxy
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(714,27): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(711): message : while compiling class template member function 'std::vector<int,Alloc>::~vector(void) noexcept'
1>C:\code\dumpster\Project1\Project1\main.cpp(36): message : see reference to function template instantiation 'std::vector<int,Alloc>::~vector(void) noexcept' being compiled
1>C:\code\dumpster\Project1\Project1\main.cpp(36): message : see reference to class template instantiation 'std::vector<int,Alloc>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(714,25): error C2530: '_Alproxy': references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): error C3536: '_Alproxy': cannot be used before it is initialized
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,9): error C2672: '_Delete_plain_internal': no matching overloaded function found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): error C2893: Failed to specialize function template 'void std::_Delete_plain_internal(_Alloc &,_Alloc::value_type *const ) noexcept'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\xmemory(998): message : see declaration of 'std::_Delete_plain_internal'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): message : With the following template arguments:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): message : '_Alloc=int'
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Edit
I opened a bug ticket for the msvc devs.

It does not.
An allocator rebound to a different value type must be constructible from the original allocator - this is the A a(b) row in the requirements you linked.
Your type fails that requirement.

Related

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.

Thread std::invoke unknown type and failed to specialize function error

I tried to use thread at in function and send parameter as pointer class, i take errors that Error C2672 'std::invoke': no matching overloaded function found and Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
I search a lot but only i found that about this error everyone forget to send parameter.I did not forget but i still have these errors.
My function as like below
Function Listen
void Listen(can* _c) {
while (_c->s != INVALID_SOCKET)
{
auto t = thread( &connect_tcp::Recv_data,_c->connection, _c->s,ref(_c->response), _c->signals ); //ERROR IS HERE
t.join();
}
}
Class can
class can {
public:
Cotp_connection cotp;
mms mms_obj;
connect_tcp* connection;
mms_response response;
LinkedList** list;
all_size_encoder size_encoder;
SOCKET s;
Signals* signals;
};
Class connect_tcp
class connect_tcp
{
public:
SOCKET ConnectWithTcp();
int send_data(SOCKET s, LinkedList** list,int &j);
connect_tcp();
connect_tcp(char* ip, int set_port);
void Close_tcp(SOCKET s);
void Recv_data(SOCKET s,mms_response &response, Signals *signals);
std::mutex mutex;
private:
SOCKET server;
SOCKADDR_IN addr;
int port;
WSADATA WSAData;
};
Function Recv_data
void connect_tcp::Recv_data(SOCKET s,mms_response &response,Signals *signals) {
LinkedList** list = new LinkedList * [1000];
uint8_t* buffer = new uint8_t [10000];
Sleep(1000);
std::lock_guard<std::mutex>guard(mutex);
recv(s, (char*)buffer, 10000, 0);
/*this->mutex.unlock();*/
decode_bytes(response,buffer, list,signals);
}
At auto t = thread( &connect_tcp::Recv_data,_c->connection, _c->s,ref(_c->response), _c->signals );
connect_tcp::Recv_data is my member function and _c->connection is my object that storage the member function, and other variables are function's parameters.
I tried everything that i saw and read but i got these errors everytime, i cannot find to solve this.
If you want to explore classes more than my writings. I can edit this post.
Building output
1>------ Build started: Project: kkkkk_v2, Configuration: Debug x64 ------
1>fake_main.cpp
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\byte_decode.h(78,94): warning C4138: '*/' found outside of comment
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\connect_tcp.cpp(45,3): warning C4551: function call missing argument list
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(40,14): error C2672: 'std::invoke': no matching overloaded function found
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : see reference to function template instantiation 'unsigned int std::thread::_Invoke<_Tuple,0,1>(void *) noexcept' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : with
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : [
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : _Tuple=_Tuple
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : ]
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : see reference to function template instantiation 'unsigned int (__cdecl *std::thread::_Get_invoke<_Tuple,0,1>(std::integer_sequence<unsigned __int64,0,1>) noexcept)(void *)' being compiled
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : see reference to function template instantiation 'std::thread::thread<int(__cdecl &)(SOCKET,int),can*&,void>(_Fn,can *&)' being compiled
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : with
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : [
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : _Fn=int (__cdecl &)(SOCKET,int)
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : ]
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\chrono(669): message : see reference to class template instantiation 'std::chrono::duration<double,std::ratio<1,1>>' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\chrono(177): message : see reference to class template instantiation 'std::chrono::duration<__int64,std::nano>' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\chrono(647): message : see reference to class template instantiation 'std::chrono::time_point<std::chrono::steady_clock,std::chrono::steady_clock::duration>' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\type_traits(1571): message : see declaration of 'std::invoke'
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): message : With the following template arguments:
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): message : '_Callable=int (__cdecl *)(SOCKET,int)'
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): message : '_Types={can *}'
1>Done building project "kkkkk_v2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The first argument to std::thread is a callable object which is defined like this:
template< class Function, class... Args >
explicit thread( Function&& f, Args&&... args );
This callable object must be callable with this syntax:
f()
But in your example you are passing a member function pointer to the construction of std::thread and the correct syntax to call a member function pointer is like this:
(calleeObject->*fp)()
So you cannot pass a member function pointer to the constructor of std::thread. The easy way to solve it would be using a lambda as your callable object:
std::thread([=_c]()
{
_c->connection->Recv_data(_c->s, ref(_c->response), _c->signals);
});
or you can use std::mem_fn adapter and include your callee object in your parameters list too as you did it in your own code:
std::thread(std::mem_fn(&connect_tcp::Recv_data), _c->connection, _c->s, ref(_c->response), _c->signals);

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

Using an external class in templated method from dll

I'm trying to use my game engine into an external project. Everything works fine but I have a problem when I'm trying to create a custom component (That inherits from ABhaviour which is an abstract class representing a component that can be activated/disabled).
GameObject.h (exported with __declspec(dllexport))
// [...]
template <typename Class, typename ... Args>
std::shared_ptr<Class> GameObject::AddComponent(Args... args)
{
auto newComp = std::make_shared<Class>(std::forward<Args>(args)...);
m_components[typeid(*newComp).hash_code()] = newComp;
m_components[typeid(*newComp).hash_code()]->SetOwner(*this);
return newComp;
}
// [...]
In an other project (That use my game engine), I'm trying to create the custom ABehaviour :
PlayerController.h
#pragma once
#include <ElkGameEngine/Objects/Components/Behaviours/ABehaviour.h>
class PlayerController :ElkGameEngine::Objects::Components::Behaviours::ABehaviour
{
PlayerController() = default;
~PlayerController() = default;
void Update();
};
After that I add my custom component onto my "Player" GameObject :
Main.cpp
#include <ElkGameEngine/ElkGameEngine.h>
#include <ElkGameEngine/Objects/AObject.h>
#include <ElkGameEngine/Objects/Components/AComponent.h>
#include "PlayerController.h"
using namespace ElkGameEngine::Objects::Components;
using namespace ElkGameEngine::Objects::Components::Behaviours;
int main()
{
ElkGameEngine::Managers::EngineManager elkGameEngine;
elkGameEngine.GetSceneManager()->CreateScene("ElkCraft");
auto& player = elkGameEngine.GetSceneManager()->CreateEmptyGameObject("Player");
player.AddComponent<PlayerController>(); /* Here is the problem */
while (elkGameEngine.IsRunning())
{
elkGameEngine.PreUpdate();
elkGameEngine.PostUpdate();
}
return EXIT_SUCCESS;
}
Visual Studio is unhappy and print me this :
Severity Code Description Project File Line Suppression State
Error C2440 '<function-style-cast>': cannot convert from 'const std::shared_ptr<PlayerController>' to 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>' ElkCraft c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory 1472
Error C2228 left of '.swap' must have class/struct/union ElkCraft c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory 1472
Output window :
1>------ Build started: Project: ElkCraft, Configuration: Debug x64 ------
1>Could Not Find C:\Users\adrie\Desktop\GROUP_2\PFA\ElkCraft\*.dll
1>main.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): error C2440: '<function-style-cast>': cannot convert from 'const std::shared_ptr<PlayerController>' to 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\adrie\desktop\group_2\pfa\elkengine\build\elkgameengine\include\elkgameengine\objects\gameobject.h(53): note: see reference to function template instantiation 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent> &std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>::operator =<PlayerController>(const std::shared_ptr<PlayerController> &) noexcept' being compiled
1>c:\users\adrie\desktop\group_2\pfa\elkengine\build\elkgameengine\include\elkgameengine\objects\gameobject.h(55): note: see reference to function template instantiation 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent> &std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>::operator =<PlayerController>(const std::shared_ptr<PlayerController> &) noexcept' being compiled
1>c:\users\adrie\desktop\group_2\pfa\elkcraft\sources\main.cpp(18): note: see reference to function template instantiation 'std::shared_ptr<PlayerController> ElkGameEngine::Objects::GameObject::AddComponent<PlayerController,>(void)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): error C2228: left of '.swap' must have class/struct/union
1>Generating Code...
1>Compiling...
1>PlayerController.cpp
1>Generating Code...
1>Done building project "ElkCraft.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think that the problem come from the fact that my game engine (Which is a group of DLL) is exporting a templated method (AddComponent and other ones like GetComponent).
Is it possible to use a templated method from a dll with a class/struct template argument from the project using the dll ?
Am I doing something wrong ?
Do I need to specify something on my PlayerController to make it "known/usable" in the AddComponent method ?

Confirm This Standard Library Bug Relating to Allocators in MSVC 2015 RC

Here is a SSCCE:
#include <memory>
#include <vector>
template <class T> struct my_allocator : std::allocator<T> {
//This overriding struct causes the error
template <class U> struct rebind {
typedef my_allocator<T> other;
};
//Ignore all this.
typedef std::allocator<T> base;
typename base::pointer allocate(typename base::size_type n, std::allocator<void>::const_pointer /*hint*/=nullptr) { return (T*)malloc(sizeof(T)*n); }
void deallocate(typename base::pointer p, typename base::size_type /*n*/) { free(p); }
};
int main(int /*argc*/, char* /*argv*/[]) {
std::vector<int,my_allocator<int>> vec;
return 0;
}
GCC likes it.
ICC likes it.
Clang likes it.
Even MSVC 2013 likes it.
But MSVC 2015 RC spits out:
1>------ Build started: Project: Test Alloc, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(579): error C2664: 'void std::_Wrap_alloc<my_allocator<int>>::deallocate(int *,unsigned int)': cannot convert argument 1 from 'std::_Container_proxy *' to 'int *'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(579): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(574): note: while compiling class template member function 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)'
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(541): note: see reference to function template instantiation 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)' being compiled
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(668): note: see reference to class template instantiation 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>' being compiled
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\users\ian mallett\desktop\test-alloc\main.cpp(18): note: see reference to class template instantiation 'std::vector<int,my_allocator<int>>' being compiled
Related program give similarly fishy sounding errors. Here are two:
error C2664: 'void std::_Wrap_alloc>::deallocate(int *,unsigned int)': cannot convert argument 1 from 'std::_Container_proxy *' to 'int *'
cannot convert argument 1 from 'std::_Wrap_alloc>' to 'const aligned_allocator &'
Boolean question: is this a bug? Iff it is, I will (try) to submit it.
[EDIT: as noted in the comments, this only occurs in debug mode. In release mode, it compiles and executes fine.]
[EDIT: much simpler example]
Boolean question: is this a bug?
false.
Although the template error given by MSVC here is surpassingly unhelpful, the error here is mine (reassuring since this version of the standard library is shipping today).
I created this allocator (and later, the reduced test case) from a variety of sources, which is why I assumed it was correct. However, as suggested in the comments, I checked again, this time exhaustively against the documentation.
The missing component here is one of the copy constructors (the template one that can't be auto-generated). This only shows up when the rebind struct is defined since the rebind struct overrides the same struct in the parent class (which, since it's in the parent class, ultimately causes the parent's copy constructor to be called, so there's no problem (except that it's technically wrong)).
The interesting thing here is that the error didn't occur until now. As I said, GCC, Clang, and MSVC 2013 all like it (even with their respective debug modes). It's just that none of these happened to call the template copy constructor. Nevertheless, it is specified by the standard, so again, the error is ultimately mine.
Congratulations to the MSVC compiler team, and sorry for the noise! :D