Menu

#612 ostream& operator<<(ostream& o, CallEndReason reason) is ambiguous

Stable_Branch
open
None
5
2022-08-12
2022-08-12
d153859
No

PTLib/OPAL 2.18.8/3.18.8 release bundle.

Consider the following application code:

PStringStream reasonStr;
reasonStr << call.GetCallEndReason();

In opal/connction.cxx, operator '<<' is defined as:

#if PTRACING
ostream & operator<<(ostream & out, OpalConnection::CallEndReason reason)
{
    ...
    default :
      return out << reason.code; // <- reason.code is int
  }
}
#endif

So it prints out an integer enum value.

In opal/connction.h, enum CallEndReasonCodes in defined as:

    P_DECLARE_TRACED_ENUM_EX(CallEndReasonCodes,NumCallEndReasons,
      EndedByLocalUser,0,            ///< Local endpoint application cleared call
    ...

In ptlib/object.h:

#if PTRACING
...
#define P_DECLARE_TRACED_ENUM_EX P_DECLARE_STREAMABLE_ENUM_EX
...
#define P_DECLARE_STREAMABLE_ENUM_EX(...) \
  P_DECLARE_ENUM_EX(...) \
  P_DECLARE_ENUM_NAMES(...)

... and finally...

#define P_DECLARE_ENUM_NAMES(name, ...) \
...
  friend __inline std::ostream & operator<<(std::ostream & strm, name e) \
    { PPrintEnum(strm, e, Begin##name, End##name, PEnumNames_##name::Names()); return strm; } \
...

If PTRACING is defined, operator<<() becomes ambiguous. In VS2019 the compiler generates code to call operator<< that prints a string, but gcc for Linux - to call the first one printing an integer.

Suggested solution:
In opal/connction.h and opal/connction.cxx, change conditional

#if PTRACING

to

#if !PTRACING

Discussion


Log in to post a comment.

MongoDB Logo MongoDB