c++.stlsoft - [STLSoft-1.9.44] allocator problem with class clipboard_scope under
- Martin Moene <m.j.moene eld.physics.LeidenUniv.nl> Jun 16 2008
- Matt Wilson <matthewwilson acm.org> Aug 12 2008
Hi Matthew,
Compiling the program below with Visual C++ 8 gives an error.
In function set_data_or_deallocate_and_throw_ HANDLE (being deallocated) is
incompatible with the allocator's char* type.
Changing lines 269-271 from:
269 private:
270 template <ss_typename_param_k A>
271 void set_data_or_deallocate_and_throw_(UINT fmt, HANDLE hData, A&
ator) stlsoft_throw_1(clipboard_scope_exception)
to
269 private:
270 template <ss_typename_param_k C, ss_typename_param_k A>
271 void set_data_or_deallocate_and_throw_(UINT fmt, C* hData, A& ator)
stlsoft_throw_1(clipboard_scope_exception)
seems to solve the issue.
Cheers, Martin.
___
#include <winstl/clipboard/clipboard_scope.hpp>
#include <algorithm> // std::copy
#include <iostream> // std::cout, std::endl
int main()
{
try
{
// set the data on the clipboard:
{
winstl::clipboard_scope scope;
scope.set_data( "Text from clipboard_scope demo." );
}
// as long as no other thread/process changes the clipboard contents
// in the meanwhile, this can then be read back, as follows:
{
winstl::clipboard_scope scope;
char const *cstr;
scope.get_data( cstr );
std::cout << "Clipboard data: " << cstr << std::endl;
// scope.get_allocator().do_deallocate( cstr ); // private!
}
}
catch( std::exception const& e )
{
std::cerr << "Exception: " << e.what() << std::endl;
}
}
___
cl -nologo -W3 -EHsc -I"D:\Libraries\stlsoft-1.9.44/include"
-D"WINVER=0x0400" -D"_CRT_SECURE_NO_DEPRECATE" -D"_SCL_SECURE_NO_DEPRECATE"
user32.lib Psapi.lib wininet.lib ws2_32.lib winstl_clipboard_scope.cpp
winstl_clipboard_scope.cpp
D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(284)
: error C2664: 'void stlsoft::allocator_base<T,A>::deallocate(char *)' :
cannot convert parameter 1 from 'HANDLE' to 'char *'
with
[
T=char,
A=stlsoft::winstl_project::global_allocator<char>
]
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(382)
: see reference to function template instantiation 'void
stlsoft::winstl_project::clipboard_scope::set_data_or_deallocate_and_throw_<stlsoft::winstl_project::global_allocat
r<T>>(UINT,HANDLE,A
&) throw(stlsoft::winstl_project::clipboard_scope_exception)' being compiled
with
[
T=char,
A=stlsoft::winstl_project::global_allocator<char>
]
D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(284)
: error C2664: 'void stlsoft::allocator_base<T,A>::deallocate(wchar_t *)' :
cannot convert parameter 1 from 'HANDLE' to 'wchar_t *'
with
[
T=wchar_t,
A=stlsoft::winstl_project::global_allocator<wchar_t>
]
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(406)
: see reference to function template instantiation 'void
stlsoft::winstl_project::clipboard_scope::set_data_or_deallocate_and_throw_<stlsoft::winstl_project::global_allocat
r<T>>(UINT,HANDLE,A
&) throw(stlsoft::winstl_project::clipboard_scope_exception)' being compiled
with
[
T=wchar_t,
A=stlsoft::winstl_project::global_allocator<wchar_t>
]
___
File winstl/clipboard/clipboard_scope.hpp
private:
template <ss_typename_param_k A>
void set_data_or_deallocate_and_throw_(UINT fmt, HANDLE hData, A& ator)
stlsoft_throw_1(clipboard_scope_exception)
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
try
{
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
set_data(fmt, hData);
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
}
catch(...)
{
LINE 284 ator.deallocate(hData); <========= LINE 284
throw;
}
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
___
Jun 16 2008
Hi Martin Thanks for this. It'll be incorporated into the next release. Martin Moene Wrote:Hi Matthew, Compiling the program below with Visual C++ 8 gives an error. In function set_data_or_deallocate_and_throw_ HANDLE (being deallocated) is incompatible with the allocator's char* type. Changing lines 269-271 from: 269 private: 270 template <ss_typename_param_k A> 271 void set_data_or_deallocate_and_throw_(UINT fmt, HANDLE hData, A& ator) stlsoft_throw_1(clipboard_scope_exception) to 269 private: 270 template <ss_typename_param_k C, ss_typename_param_k A> 271 void set_data_or_deallocate_and_throw_(UINT fmt, C* hData, A& ator) stlsoft_throw_1(clipboard_scope_exception) seems to solve the issue. Cheers, Martin. ___ #include <winstl/clipboard/clipboard_scope.hpp> #include <algorithm> // std::copy #include <iostream> // std::cout, std::endl int main() { try { // set the data on the clipboard: { winstl::clipboard_scope scope; scope.set_data( "Text from clipboard_scope demo." ); } // as long as no other thread/process changes the clipboard contents // in the meanwhile, this can then be read back, as follows: { winstl::clipboard_scope scope; char const *cstr; scope.get_data( cstr ); std::cout << "Clipboard data: " << cstr << std::endl; // scope.get_allocator().do_deallocate( cstr ); // private! } } catch( std::exception const& e ) { std::cerr << "Exception: " << e.what() << std::endl; } } ___ cl -nologo -W3 -EHsc -I"D:\Libraries\stlsoft-1.9.44/include" -D"WINVER=0x0400" -D"_CRT_SECURE_NO_DEPRECATE" -D"_SCL_SECURE_NO_DEPRECATE" user32.lib Psapi.lib wininet.lib ws2_32.lib winstl_clipboard_scope.cpp winstl_clipboard_scope.cpp D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(284) : error C2664: 'void stlsoft::allocator_base<T,A>::deallocate(char *)' : cannot convert parameter 1 from 'HANDLE' to 'char *' with [ T=char, A=stlsoft::winstl_project::global_allocator<char> ] Conversion from 'void*' to pointer to non-'void' requires an explicit cast D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(382) : see reference to function template instantiation 'void stlsoft::winstl_project::clipboard_scope::set_data_or_deallocate_and_throw_<stlsoft::winstl_project::global_allocat r<T>>(UINT,HANDLE,A &) throw(stlsoft::winstl_project::clipboard_scope_exception)' being compiled with [ T=char, A=stlsoft::winstl_project::global_allocator<char> ] D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(284) : error C2664: 'void stlsoft::allocator_base<T,A>::deallocate(wchar_t *)' : cannot convert parameter 1 from 'HANDLE' to 'wchar_t *' with [ T=wchar_t, A=stlsoft::winstl_project::global_allocator<wchar_t> ] Conversion from 'void*' to pointer to non-'void' requires an explicit cast D:\Libraries\stlsoft-1.9.44/include\winstl/clipboard/clipboard_scope.hpp(406) : see reference to function template instantiation 'void stlsoft::winstl_project::clipboard_scope::set_data_or_deallocate_and_throw_<stlsoft::winstl_project::global_allocat r<T>>(UINT,HANDLE,A &) throw(stlsoft::winstl_project::clipboard_scope_exception)' being compiled with [ T=wchar_t, A=stlsoft::winstl_project::global_allocator<wchar_t> ] ___ File winstl/clipboard/clipboard_scope.hpp private: template <ss_typename_param_k A> void set_data_or_deallocate_and_throw_(UINT fmt, HANDLE hData, A& ator) stlsoft_throw_1(clipboard_scope_exception) { #ifdef STLSOFT_CF_EXCEPTION_SUPPORT try { #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */ set_data(fmt, hData); #ifdef STLSOFT_CF_EXCEPTION_SUPPORT } catch(...) { LINE 284 ator.deallocate(hData); <========= LINE 284 throw; } #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */ } ___
Aug 12 2008








Matt Wilson <matthewwilson acm.org>