c++/10245: regression in 3.3, C++ ternary operator confuses type lookup

harri.pasanen@trema.com harri.pasanen@trema.com
Thu Mar 27 17:55:00 GMT 2003


>Number:         10245
>Category:       c++
>Synopsis:       regression in 3.3, C++ ternary operator confuses type lookup
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 27 17:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     harri.pasanen@trema.com
>Release:        unknown-1.0
>Organization:
>Environment:
gcc version 3.3 20030326 (prerelease)
>Description:
// Ternary operator throws the type resolution of balance.

namespace Type
{
  struct Date {
    int foo;
  };
};

typedef int fc_Date;

struct from_date
{
  const fc_Date &_date;
  from_date (const fc_Date &date) throw ()
    : _date (date) {}

  // Operator to convert to type date.
  operator Type::Date () const throw ()
    { Type::Date tem;
      return tem; }
private:
  // Not implemented.
  from_date ();
  from_date (const from_date &);
};

fc_Date aday() { return 1; }

#ifdef BUG
void foo()
{
  fc_Date adate, bdate;
  Type::Date d = (aday () != 0 ? from_date (adate) : from_date (bdate));
}
#else
void foo()
{
  fc_Date adate, bdate;
  Type::Date d;
  if (aday () != 0)
    d = from_date (adate);
  else
    d = from_date (bdate);
}
#endif
>How-To-Repeat:
Save the code above to file gccbug.cxx
g++ -c -DBUG gccbug.cxx
will fail to compile it g++ is 3.3 snapshot  20030326, with the message:
gccbug.cxx: In function `void foo()':
gccbug.cxx:23: error: `from_date::from_date(const from_date&)' is private
gccbug.cxx:32: error: within this context
gccbug.cxx:23: error: `from_date::from_date(const from_date&)' is private
gccbug.cxx:32: error: within this context

The -DBUG can be used to illustrate the bug in 3.3 snapshot. 
 g++ 2.96, 3.0.4 and 3.2.2 all compile the example both  with and without -DBUG.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list