EDG可能是sozeof BUG [英] EDG possible sozeof BUG
问题描述
我有以下代码,一个特征的一部分来检测一个类型
有一个成员运算符Type (),它可以正常使用g ++ 3.4(msvc
编译它但它不适用于模板'运算符T())但是
使用CBuilderX( EDG前端)和Comeau的在线编译器我得到:
test.cpp:23:错误无效的类型转换在
实例化X期间检测到:: operator T()[with T = int&]"第41行
即它实例化X :: operator< int& > int& ()在
sizeof里面,除了EDG以外的任何其他编译器我会自动认为这是一个编译器错误。
想到了吗?
#include< iostream>
#include< iomanip>
模板< typename T,typename Type>
struct has_conversion_operator
{
private:
template< typename V,Type(V :: * M)()> struct empty_t_;
template< typename U>
static char helper_f(empty_t_< U,& U :: operator Type> *);
template< typename U>
静态字符(& helper_f(...))[2];
public:
static bool const bool_value =
(sizeof(helper_f< T>(0))== sizeof(char))
;
} ;
struct X
{
template< typename T>
运算符T(){return T(); } //第23行
};
int main()
{
使用命名空间std;
cout<< boolalpha;
#define TEST(X,Y)\
cout \
<< #X 运营商 #Y"()" \
<< has_conversion_operator< X,Y> :: bool_value \
<< ''\ n''
TEST(X,int);
TEST(X,int&); //第41行
}
TIA。
Rob。
- -
http://www.victim-prime.dsl。 pipex.com/
I have the following code , part of a trait to detect wether a type
has a member operator "Type" (), it works fine with g++ 3.4 (msvc
compiles it but it doesn''t work for template''d operator T ()) but
with CBuilderX (EDG frontend) and Comeau''s online compiler I get:
test.cpp:23: error invalid type conversion detected during
instantiation of "X::operator T() [with T=int &]" at line 41
I.e it instantiates X::operator< int & > int & () inside the
sizeof, any other compiler than EDG and I''d automaticly think
this was a compiler bug.
Thought''s ?
#include <iostream>
#include <iomanip>
template < typename T, typename Type >
struct has_conversion_operator
{
private:
template < typename V, Type (V::*M)() > struct empty_t_;
template < typename U >
static char helper_f( empty_t_< U, &U::operator Type > * );
template < typename U >
static char (&helper_f( ... ))[2];
public:
static bool const bool_value =
( sizeof( helper_f< T >( 0 ) ) == sizeof( char ) )
;
};
struct X
{
template < typename T >
operator T () { return T(); } // line 23
};
int main()
{
using namespace std;
cout << boolalpha;
#define TEST( X, Y ) \
cout \
<< #X " operator " #Y "() " \
<< has_conversion_operator< X, Y >::bool_value \
<< ''\n''
TEST( X, int );
TEST( X, int & ); // line 41
}
TIA.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
推荐答案
Rob Williscroft写道:
Rob Williscroft wrote:
我有以下代码,部分是用于检测类型的特征
具有成员操作员类型。 (),它适用于g ++ 3.4(msvc
编译它,但它不适用于模板'运算符T())但是使用CBuilderX(EDG前端)和Comeau''在线编译器我得到:
test.cpp:23:在X :: operator T()[with T = int&]的实例化过程中检测到错误无效的类型转换第41行
它实例化X :: operator< int& > int& ()在sizeof内,除了EDG以外的任何其他编译器,我都会自动认为这是一个编译器错误。
思想是什么?
我很难理解你的写作,对不起。我确定这是
不是你的错。你只是把这种独特的风格放在一起
句子让我感到厌烦。但有一点我认为我应该提一下:
用T == int&来实现T()是不可能的。引用必须初始化为
。也许这就是你得到错误的原因。 无效类型
转换可能只是糟糕的措辞。
#include< iostream>
#include< iomanip>
模板< typename T,typename Type>
struct has_conversion_operator
{
private:
template< typename V,Type(V :: * M)()> struct empty_t_;
模板< typename U>
static char helper_f(empty_t_< U,& U :: operator Type> *);
template< typename U>
static char(& helper_f(...))[2];
public:
static bool const bool_value =
(sizeof( helper_f< T>(0))== sizeof(char))
;
};
struct X
{
模板< typename T>
运算符T(){return T(); } //第23行
};
int main()
{
使用命名空间std;
cout<< boolalpha;
#define TEST(X,Y)\
cout \
<< #X 运营商 #Y"()" \
<< has_conversion_operator< X,Y> :: bool_value \
<< ''\ n''
TEST(X,int);
TEST(X,int&); //第41行
} TIA。
Rob。
I have the following code , part of a trait to detect wether a type
has a member operator "Type" (), it works fine with g++ 3.4 (msvc
compiles it but it doesn''t work for template''d operator T ()) but
with CBuilderX (EDG frontend) and Comeau''s online compiler I get:
test.cpp:23: error invalid type conversion detected during
instantiation of "X::operator T() [with T=int &]" at line 41
I.e it instantiates X::operator< int & > int & () inside the
sizeof, any other compiler than EDG and I''d automaticly think
this was a compiler bug.
Thought''s ?
I have hard time understanding your writing, sorry. I am sure it is
not your fault. You just have this unique style of putting together
sentences that escape me. But one thing I think I should mention:
it''s impossible to instantiate T() with T == int&. References have to
be initialised. Perhaps that''s why you get the error. "invalid type
conversion" may just be bad wording.
#include <iostream>
#include <iomanip>
template < typename T, typename Type >
struct has_conversion_operator
{
private:
template < typename V, Type (V::*M)() > struct empty_t_;
template < typename U >
static char helper_f( empty_t_< U, &U::operator Type > * );
template < typename U >
static char (&helper_f( ... ))[2];
public:
static bool const bool_value =
( sizeof( helper_f< T >( 0 ) ) == sizeof( char ) )
;
};
struct X
{
template < typename T >
operator T () { return T(); } // line 23
};
int main()
{
using namespace std;
cout << boolalpha;
#define TEST( X, Y ) \
cout \
<< #X " operator " #Y "() " \
<< has_conversion_operator< X, Y >::bool_value \
<< ''\n''
TEST( X, int );
TEST( X, int & ); // line 41
}
TIA.
Rob.
V
V
Victor Bazarov在新闻中写道:5wzdd.5994
Victor Bazarov wrote in news:5wzdd.5994
Ae.5220
@ newsread1.dllstx09.us.to comp.lang.c中的.verio.net ++:
Ae.5220
@newsread1.dllstx09.us.to.verio.net in comp.lang.c++:
我很难理解你的写作,抱歉。我相信这不是你的错。你只是把这种独特的风格拼凑起来,让我感到惊讶。
我怀疑是我。仅仅因为英语是我的第一语言并不是
意味着我实际上对它有任何好处:)。
但有一件事我想我应该提到:<用T == int&来实例化T()是不可能的。参考文献必须初始化。也许这就是你得到错误的原因。 无效类型
转换可能只是糟糕的措辞。
I have hard time understanding your writing, sorry. I am sure it is
not your fault. You just have this unique style of putting together
sentences that escape me.
I suspect its me. Just because English is my first language doesn''t
mean I''m actually any good at it :).
But one thing I think I should mention:
it''s impossible to instantiate T() with T == int&. References have to
be initialised. Perhaps that''s why you get the error. "invalid type
conversion" may just be bad wording.
是的,我理解为什么会员的功能体不能被实例化。
但是我不明白为什么EDG将其实例化为
sizeof表达式。
函数的主体应该*永远不需要编译
时间表达式(因为它无论如何都不能使用:)。
Rob。
-
http://www.victim -prime.dsl.pipex.com/
这篇关于EDG可能是sozeof BUG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!