Showing results for 
Search instead for 
Do you mean 

Bool/int confusion

Highlighted
Occasional Visitor

Bool/int confusion

It's admittedly been a long time since I've done any real work in C++, and this has been killing me for a few days now. We are migrating to an Itanium server, and I'm getting this compiler error:

"collector.C", line 41: error #2418: more than one conversion function from
"mmm::predicate" to a built-in type applies:
function "mmm::predicate::operator bool() [with T=int]"
function "mmm::predicate::operator T &() [with T=int]"

The actual (relevant) code is:
template
class predicate {
public:
virtual operator bool();
T &operator=(T v);
operator T&();
.........

Finally, the entire, overly verbose compile statement (I love makefiles):
Compiling collector.C
/opt/aCC/bin/aCC -g0 -AP -v -w +z +Z +Maked +DD32 -DNOWHAT -I. -I/opt/siadev/jwinkle/SIA/DASC/include -I/opt/siadev/jwinkle/SIA/include_r -I/opt/EA2000_3.5.1.4/include -I. -I/opt/siadev/jwinkle/SIA/DASC/adapter/include -I/opt/siadev/jwinkle/SIA/DASC/common/include -I/opt/siadev/jwinkle/SIA/DASC/adapter/include -I/opt/siadev/jwinkle/SIA/include -I/opt/siadev/jwinkle/SIA/DASC/SAQ/external/include -I/opt/tuxdir/tuxedo8.1/include -I/opt/topcom/5.6/build/inc -I/usr/include -c collector.C
/opt/aCC/lbin/ecom -architecture 32 -makedepend file -ia64abi all -diag off -inst compiletime -sysdir /usr/include -inline_power 1 -link_type dynamic -fpeval float -fpevaldec _Decimal32 -tls_dyn on -target_os 11.23 -I. -I/opt/siadev/jwinkle/SIA/DASC/include -I/opt/siadev/jwinkle/SIA/include_r -I/opt/EA2000_3.5.1.4/include -I. -I/opt/siadev/jwinkle/SIA/DASC/adapter/include -I/opt/siadev/jwinkle/SIA/DASC/common/include -I/opt/siadev/jwinkle/SIA/DASC/adapter/include -I/opt/siadev/jwinkle/SIA/include -I/opt/siadev/jwinkle/SIA/DASC/SAQ/external/include -I/opt/tuxdir/tuxedo8.1/include -I/opt/topcom/5.6/build/inc -I/usr/include --sys_include /opt/aCC/include --sys_include /opt/aCC/include/iostream --sys_include /usr/include --sys_include /usr -D_HP_IA64ABI -D_BIND_LIBCALLS -D_Math_errhandling=MATH_ERREXCEPT -D__hpux -D__unix -D__ia64=1 -D__ia64__=1 -D_BIG_ENDIAN=1 -D__STDCPP__ -D_ILP32 -D__cplusplus=199711L -D__HP_aCC=62000 -D_HP_INSTANTIATE_T_IN_LIB -D_INLINE_ASM -D_FLT_EVAL_METHOD=0 -D_DEC_EVAL_METHOD=0 -DNOWHAT -debug debugG -ucode hdriver=optlevel%1% -plusolistoption -Ol06all! -plusolistoption -Ol13moderate! -plusooption -Oq01,al,ag,cn,sz,ic,vo,Mf,Po,es,rs,Rf,Pr,sp,in,cl,om,vc,pi,fa,pe,rr,pa,pv,nf,cp,lx,Pg,ug,lu,lb,uj,dn,sg,pt,kt,em,np,ar,rp,dl,fs,bp,wp,pc,mp,lr,cx,cr,pi,so,Rc,fa,ft,fe,ap,st,lc,Bl,sr,Qs,do,ib,pl,sd,ll,rl,dl,Lt,ol,fl,lm,ts,rd,dp,If! collector.C


WHY, oh why, does this think my bool is an int? I saw another post recently about this, and I am 100% certain that nowhere in our code is a bool being typedef, or #define'd, as an int.
4 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: Bool/int confusion

>CC -g0 -AP -v -w +z +Z -I/usr/include

Why are you using -AP? You should use the default -AA.

Instead of using -w, you should suppress individual warnings with +Wnnnn.
You should also not specify the default include file paths.

>The actual (relevant) code is:

Where is the code that is using/calling this template?

You may have to use a cast hammer and tell the compiler exactly which function you want to call

>does this think my bool is an int?

Why do you think that? It is trying to convert a something?, mmm::predicate, either to a bool or an int&.

I can duplicate the message with:
error #2418: more than one conversion function from "predicate" to a built-in type applies:
function "predicate::operator bool() [with T=int]"
function "predicate::operator T &() [with T=int]"
int i = 8 + P;

aCC3 doesn't seem to give an error.

Adding a hammer makes it work:
int i = 8 + (bool)P;
int i = 8 + static_cast(P);
Occasional Visitor

Re: Bool/int confusion

>Why are you using -AP? You should use the default -AA.

Instead of using -w, you should suppress individual warnings with +Wnnnn.
You should also not specify the default include file paths.


I took out the default include paths, FWIW. We are using -AP and -w becuase we are migrating over 200MB of code, and are essentially doing so in stages. Once it builds without errors, we'll worry about warnings.

>Where is the code that is using/calling this template?


mmm::predicate alarm;

......

"collector.C", line 154: error #2418: more than one conversion function from
"mmm::predicate" to a built-in type applies:
function "mmm::predicate::operator bool() [with T=int]"
function "mmm::predicate::operator T &() [with T=int]"
while (SIGTERM != alarm) {
^

>Why do you think that? It is trying to convert a something?, mmm::predicate, either to a bool or an int&.

My understanding is, SIGTERM is an int, and alarm is predicate, so it should be using the predicate::operator T &() functions. Confusing int and bool is the only reason I can think of for why it would be looking to predicate::operator bool() as well.

While doing a cast would work, this is used in a bunch of places, and I don't really want to make 100 edits, when hopefully 1 fix would suffice.

I'd be more than happy to be told my understandings are wrong here. I've been living in C# and scripting languages for the last 8 or 9 years, so my C++ is still a bit fuzzy.
Occasional Visitor

Re: Bool/int confusion

Acclaimed Contributor Acclaimed Contributor

Re: Bool/int confusion

>SIGTERM is an int, and alarm is predicate, so it should be using the predicate::operator T &() functions. Confusing int and bool is the only reason I can think of for why it would be looking to predicate::operator bool() as well.

The Standard says both int and bool have equal precedence in operator overloading.

>when hopefully 1 fix would suffice.

Remove the operator bool but it must be important since it is virtual.

>Found my answer here:

Right: "these conversion functions may interfere with perfectly valid conversions and overloads."