public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: implicit declaration in C++ considered harmful
@ 1998-04-08 21:20 Kaz Kylheku
  1998-04-08 17:25 ` Joe Buck
  1998-04-09 18:29 ` Martin von Loewis
  0 siblings, 2 replies; 5+ messages in thread
From: Kaz Kylheku @ 1998-04-08 21:20 UTC (permalink / raw)
  To: 'Gabriel Dos Reis', Joe Buck; +Cc: g++, egcs

On Wednesday, April 08, 1998 7:31 AM, Gabriel Dos Reis 
[SMTP:Gabriel.Dos-Reis@dptmaths.ens-cachan.fr] wrote:

> I think EGCS should be standard conforming and flags implicit
> declaration as an error not a warning.

The C and C++ standards don't distinguish errors and warnings,
though I say this with somewhat less than full confidence because
I'm not as familiar with the C++ draft as with the C standard.

Both types of messages qualify as ``diagnostics''.  A C++
compiler could treat undeclared functions as being implicitly declared
int (...) provided that it emits a diagnostic.

A conforming C compiler is allowed to translate even a
*syntactically* incorrect program, provided that it diagnoses
the syntax violation!

I believe I have seen compilers that produce
an a.out executable from an empty translation unit even
after diagnosing the error!

Another good example is compilers which allow incompatible
pointer assignments to pass by with a mere warning.
This is a constraint violation that requires a diagnostic; it
is as serious as a syntax error. The warning message
serves as an adequate diagnostic, however.


^ permalink raw reply	[flat|nested] 5+ messages in thread
* implicit declaration in C++ considered harmful
@ 1998-04-08  2:13 Joe Buck
  1998-04-08  7:35 ` Gabriel Dos Reis
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Buck @ 1998-04-08  2:13 UTC (permalink / raw)
  To: g++, egcs

I'd like to nuke the implicit declaration of functions in C++.  This
thoroughly broken feature cannot be turned off.

Yes, you get a warning, and you can make warnings errors, but the problem
is that if a user forgets to declare a function, or mistypes it, cascades
of dozens of errors can result, because g++ declares it as int foo(...),
then objects to all class objects passed to this function, then objects
to use of the result in a context where ints aren't allowed, etc.
Or else the file compiles normally, and errors aren't noticed until link
time.

Now, in the early days of C++ when we were all basically C programmers,
this hangover from K&R C may have been desirable.  But the time is overdue
to kill this sucker; these days, chances are good that most functions
I write are going to get a class object passed to them, so the default
declaration just can't be right.

First, it should be an error, not a warning.  Second, the compiler should
insert an error node, not a function returning integer, so that we don't
get a cascade of errors.

Is there anyone who really wants the existing behavior?

Joe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-04-09 18:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-08 21:20 implicit declaration in C++ considered harmful Kaz Kylheku
1998-04-08 17:25 ` Joe Buck
1998-04-09 18:29 ` Martin von Loewis
  -- strict thread matches above, loose matches on Subject: below --
1998-04-08  2:13 Joe Buck
1998-04-08  7:35 ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).