How stupid can a compiler be?!

O

Old Wolf

Ioannis Vranos said:
Canyou please point me where it is mentioned in the standard?

No, I'm not sure what to search for :) But the topic has been
discussed in previous threads here, maybe you could search them.
At any rate it's pretty clear that this is true (the conforming
compilers won't generate a diagnostic for my sample program
below, and JKop's program demonstrated the UB-ness)
If you mean by design, why not?

The function can not possibly return, so it would be silly
to generate a diagnostic saying 'function should return
a value'.
 
A

Andre Kostur

(e-mail address removed) (Old Wolf) wrote in
The function can not possibly return, so it would be silly
to generate a diagnostic saying 'function should return
a value'.

Actually, a diagnostic here would be very useful. This code indicates that
the programmer is confused. On one hand, this function cannot return since
it's in an infinite loop. On the other hand, the programmer has declared
that this function returns an int. So which is it? Does it return, or
doesn't it?
 
G

Greg Comeau

No, I'm not sure what to search for :) But the topic has been
discussed in previous threads here, maybe you could search them.
At any rate it's pretty clear that this is true (the conforming
compilers won't generate a diagnostic for my sample program
below, and JKop's program demonstrated the UB-ness)


The function can not possibly return, so it would be silly
to generate a diagnostic saying 'function should return
a value'.

And putting in the "dummy" return might generate
an unreachable statement warning, but still, maybe.
There's a few scenario's here:

* The programmer for some reason thought a return type of
int was a good idea
* The function actually returned an int, but that line
was mistaken deleted
* The function is more involved than shown above, and
most path of execution actually do return a value,
except for one like the one above

probably some others, and in some, you would want
a diagnostic, it could be an error, or warning,
or something controllable by a compiler switch.
 
G

Greg Comeau

Ioannis Vranos said:
Canyou please point me where it is mentioned in the standard?

6.6.3p2: "Flowing off the end of a function is equivalent to
a return with no value; this results in undefined behavior in
a value-returning function." Note that is referring to
runtime.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top