Topic: Ambiguous type vs. function call semantics in C++


Author: jss@lucid.com (Jerry Schwarz)
Date: 25 May 1994 18:52:13 GMT
Raw View
Doug's example:
   >   SOCK_Listener listener (INET_Addr (port_num));

Jason's comment:
   This should be parsed as a function declaration; Lucid and Microsoft are
   correct.  See the discussion in 8.1.1 of the ARM.

Jason's comment is accurate, but in fairness to cfront it should be
pointed out that the interpretation of Doug's example as an object
rather than a function declaration appears to be a deliberate feature
rather than a bug.

As far as I can determine, cfront always treats T(id) where T is a
typename and id is a simple identifier as an expression.  Even though
this conflicts with the ARM and the working paper it does seem to
agree with most programmers expectations better than the working
paper rule.

  -- Jerry Schwarz(jss@lucid.com)








Author: jason@cygnus.com (Jason Merrill)
Date: Wed, 25 May 1994 10:32:07 GMT
Raw View
>>>>> Douglas C Schmidt <schmidt@tango.ics.uci.edu> writes:

>   SOCK_Listener listener (INET_Addr (port_num));

This should be parsed as a function declaration; Lucid and Microsoft are
correct.  See the discussion in 8.1.1 of the ARM.

Jason




Author: schmidt@tango.ics.uci.edu (Douglas C. Schmidt)
Date: 24 May 1994 13:46:54 -0700
Raw View
Hi,

 I've seen several C++ compilers (Microsoft Visual C++ and
Lucid C++) that "fail" to correctly parse the following:

----------------------------------------
class INET_Addr {
public:
 INET_Addr (unsigned short);
 // ...
};

class SOCK_Listener {
public:
   SOCK_Listener (const INET_Addr &);
 int accept (void);
}

int main (void)
{
  SOCK_Listener listener (INET_Addr (port_num));
  int i;

  while ((i = listener.accept ()) != -1)
 //...
}
----------------------------------------

 The error messages say things like

>> E, CPP-server.C(15,16) Expected struct or union type, found "class
>> SOCK_Listener (*f)(INET_ Addr)"

If I make the following change, everything works fine:

----------------------------------------
  INET_Addr server_addr (port_num);
  SOCK_Listener listener (server_addr);
----------------------------------------

Other compilers (such as SunC++ 3.x and Centerline 2.x) have no
problem with this.  Does anyone know which compilers are "correct" wrt
the emerging ANSI C++ draft standard?

 Thanks,

  Doug
--
His life was gentle, and the elements so            | Douglas C. Schmidt
Mixed in him that nature might stand up             | schmidt@ics.uci.edu
And say to all the world: "This was a man."         | ucivax!schmidt
   -- In loving memory of Terry Williams (1971-1991)| (714) 856-4105