Re: Template member function cast bug in VC80SP1 (and more...)
// No, it is not an omission. Using-declaration brings in a
// name only for the purpose of overload resolution. The type
// of the name remains the same.
Thanks for the quote.
// Why do you think it's illegal? It compiles both by VC++2005
// and Comeau online compiler wihtout any warning.
No, VC2005 SP1 does NOT compile:
template <typename S>
class has_something_named_swap
{
class yes { char dummy[2]; };
typedef char no;
template <typename T>
static yes test(T*, size_t = sizeof(&T::swap));
static no test(void*, size_t = 0);
public:
static const bool value = sizeof(test( (S*)0 ))!= sizeof(no);
};
int main(int argc, char* argv[])
{
bool b1 = has_something_named_swap<double>::value;
bool b2 = has_something_named_swap<int>::value;
return 0;
}
1>------ Build started: Project: test03, Configuration: Release Win32
------
1>Compiling...
1>test03.cpp
1>.\test03.cpp(20) : error C2825: 'T': must be a class or namespace when
followed by '::'
1> .\test03.cpp(35) : see reference to class template
instantiation 'has_something_named_swap<S>' being compiled
1> with
1> [
1> S=double
1> ]
1>.\test03.cpp(20) : error C2039: 'swap' : is not a member of '`global
namespace''
1>.\test03.cpp(20) : error C2275: 'T' : illegal use of this type as an
expression
1> .\test03.cpp(26) : see declaration of 'T'
1>.\test03.cpp(20) : error C2275: 'T' : illegal use of this type as an
expression
1> .\test03.cpp(26) : see declaration of 'T'
1>.\test03.cpp(20) : error C2146: syntax error : missing ')' before
identifier 'swap'
1>.\test03.cpp(20) : error C2825: 'T': must be a class or namespace when
followed by '::'
1> .\test03.cpp(36) : see reference to class template
instantiation 'has_something_named_swap<S>' being compiled
1> with
1> [
1> S=int
1> ]
1>.\test03.cpp(20) : error C2039: 'swap' : is not a member of '`global
namespace''
1>.\test03.cpp(20) : error C2275: 'T' : illegal use of this type as an
expression
1> .\test03.cpp(26) : see declaration of 'T'
1>.\test03.cpp(20) : error C2275: 'T' : illegal use of this type as an
expression
1> .\test03.cpp(26) : see declaration of 'T'
1>.\test03.cpp(20) : error C2146: syntax error : missing ')' before
identifier 'swap'
1>Build log was saved at
"file://c:\Source\test03\test03\Release\BuildLog.htm"
1>test03 - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
// There was a topic about the same problem a couple of days
// ago:
// "Some issues with using sizeof() in template definitions"
// http://groups.google.com/group/microsoft.public.vc.language/msg/
// 4c1dac7ab6ee73ef
// I think it's a bug in VC++2005.
Thanks for the reference, I know it's a ICE in VC2003, but I find it
bizarre that the bug fix is "emit a graceful compiler error" instead of
"compile it right" :)
// Alternatively, you can use `__if_exists' compiler intrinsic:
If I understand correctly, this is not a compile-time constant
// // (problem 3: very important)
// [Did you mean (c.*memptr)(...), where `memptr' is third
// parameter?]
NO! this is the key point: I don't want to USE the runtime pointer, but
a compile-time function call (in fact I pass a pointer just to select
the right overload)
// The error is misleading. The real problem is again
// inaccessibility of `VECTOR::erase' due to private
// inheritance. Comeau online reports correct error about it.
// Once appropriate `MAP_BASE::erase' is available both Comeau
// and VC++ compile the code without any problem.
Are you sure? All compilers I tried do compile with both public/private
inheritance, including Comeau (I copied and pasted the sample I posted
previously).
VC8 SP1 instead never compiles. Which settings did you use?
1>------ Build started: Project: test03, Configuration: Release Win32
------
1>Compiling...
1>test03.cpp
1>.\test03.cpp(81) : error C2664: 'erase_gap2' : cannot convert
parameter 3 from 'overloaded-function' to
'std::_Vector_iterator<_Ty,_Alloc> (__thiscall VECTOR<T>::*
)(iterator_t)'
1> with
1> [
1> _Ty=std::pair<double,double>,
1> _Alloc=std::allocator<std::pair<double,double>>,
1> T=std::pair<double,double>,
1>
iterator_t=std::_Vector_iterator<std::pair<double,double>,std::allocator
<std::pair<double,double>>>
1> ]
1> None of the functions with this name in scope match the target
type
1> .\test03.cpp(94) : see reference to function template
instantiation 'std::_Vector_iterator<_Ty,_Alloc>
erase_gap<MAP<key_t,mapped_t>>(container_t
&,std::_Vector_iterator<_Ty,_Alloc>)' being compiled
1> with
1> [
1> _Ty=std::pair<double,double>,
1> _Alloc=std::allocator<std::pair<double,double>>,
1> key_t=double,
1> mapped_t=double,
1> container_t=MAP<double,double>
1> ]
1>Build log was saved at
"file://c:\Source\test03\test03\Release\BuildLog.htm"
1>test03 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
--
Every sequence of problems that converges to a solution
Contains a sequence of solutions that converges to a new problem.
-- Mycroft Holmes