public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* 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

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 530 bytes --]

>>>>> «Joe», Joe Buck <jbuck@synopsys.com> wrote:

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

100% agreed.

Joe> Is there anyone who really wants the existing behavior?

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

-- Gaby
"One reason that life is complex is that it has a 
real part and imaginary part." -- Andrew Koenig

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

* 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
  1 sibling, 0 replies; 5+ messages in thread
From: Martin von Loewis @ 1998-04-09 18:29 UTC (permalink / raw)
  To: kaz; +Cc: g++, egcs

> 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''.  

C++ is the same, here.

> A C++ compiler could treat undeclared functions as being implicitly
> declared int (...) provided that it emits a diagnostic.

Sure it could. I think Joe made his point: even though g++ is
currently compliant (in this respect), producing an error would be
also compliant.

The real question is which one is more desirable.

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

Right. This doesn't mean the compiler *has* to produce a program from
incorrect source :-) It may provide some non-standard extensions,
whose usage it needs to diagnose. Users of these extensions would
expect that they get a working program.

The question is whether assuming implicit declarations for global
functions is a useful extension. I agree with Joe that it isn't.

Regards,
Martin

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

* 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

* 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
  1 sibling, 0 replies; 5+ messages in thread
From: Joe Buck @ 1998-04-08 17:25 UTC (permalink / raw)
  To: Kaz Kylheku; +Cc: Gabriel.Dos-Reis, Joe, Buck, jbuck, g++, egcs

> > 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.

Yes, we technically comply, but nevertheless the current behavior
is not desirable.

^ 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  2:13 implicit declaration in C++ considered harmful Joe Buck
1998-04-08  7:35 ` Gabriel Dos Reis
1998-04-08 21:20 Kaz Kylheku
1998-04-08 17:25 ` Joe Buck
1998-04-09 18:29 ` Martin von Loewis

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).