Severe problem with TString in root_5.24.00

Dear ROOTers

The following code fragments have worked since many many years on Mac, Linux and WinXP (using VC++)
for all versions of ROOT up to version root_5.22.00:

TString MyFunctions(const char *name)
{
   DoSomething();

   if (something) return isType ? name : 0;

   if (something else) return name;
   return 0;
}

These type of functions are scattered all over my program, especially “return 0”.

However, with root_5.24.00 I get suddenly the following types of errors:

XPSUtils.cxx: In function 'TString SubString(const char*, char, char, Bool_t)':
XPSUtils.cxx:4364: error: operands to ?: have different types

XPSBase.cxx: In member function 'TString XTreeSet::FindTree(const char*)':
XPSBase.cxx:1145: error: conversion from 'int' to 'TString' is ambiguous
/Volumes/CoreData/ROOT/root/include/TString.h:231: note: candidates are: TString::TString(char)
/Volumes/CoreData/ROOT/root/include/TString.h:228: note:                 TString::TString(const char*)

These errors occur whenever I “return 0;” for TString.
Why is it no longer possible to “return 0;” for TString?

In principle I could do everywhere ‘return “”;’ but for every C++ class it must be possible to return 0.

Best regards
Christian

Hi Christian,

for safety reasons we decided to make the TString(Int_t) ctor explicit. What happened in you code is that a TString(0) was created and returned, which is a string of 0 preallocated length and not 0 converted to a “0” string (as is done with TString s; s+=0;). To avoid any confusion we made this conversion explicit. Now you either have to return:

return TString(0)

or

return “”;

which is the empty string.

Returning 0 is only supported for all functions returning a pointer, not for the ones returning objects (unless they have a non-explicit MyClass(int) ctro).

Cheers, Fons.

Dear Fons

Thank you for this clarification.
I will use TString(0) and hope that it will not cause any unwanted side effects.

Best regards
Christian