This is ridiculous!

T

Tomás

#include <string>
#include <iostream>
using std::cout;
using std::endl;

void FunctionThatModifies(std::string &a)
{
a = "You've been modified.";
}


int main()
{
std::string const a("Untouchable.");


std::string &b = a; //Actually compiles with error!


FunctionThatModifies(b);


std::cout << b;
}


Compiler gives me a warning. I think it should give me a downright error,
and I want it to give me a downright error.

Firstly, does the Standard say whether this should generate a warning or
an error?

Secondly, do compilers have an option whereby you can make it give an
error? If so, I'll be using it.


-Tomás
 
A

Alf P. Steinbach

* Tomás:
std::string const a("Untouchable.");
std::string &b = a; //Actually compiles with error!

Compiler gives me a warning. I think it should give me a downright error,
and I want it to give me a downright error.

It should not compile.

Firstly, does the Standard say whether this should generate a warning or
an error?

An error.

Secondly, do compilers have an option whereby you can make it give an
error? If so, I'll be using it.

Compiler options are compiler-specific; check your compiler's help text
and/or documentation.
 
P

Pete Becker

Tomás said:
Compiler gives me a warning. I think it should give me a downright error,
and I want it to give me a downright error.

Firstly, does the Standard say whether this should generate a warning or
an error?

It requires "a diagnostic." The standard doesn't talk about warnings and
errors.
Secondly, do compilers have an option whereby you can make it give an
error? If so, I'll be using it.

Many do.
 
J

Joe Van Dyk

Alf P. Steinbach wrote:



The Standard requires "a diagnostic." It does not specify the form or
the consequences of that diagnostic, and it does not distinguish between
a "warning" and an "error."

What is "a diagnostic"?
 
D

Default User

Joe said:
What is "a diagnostic"?

From the standard, under Terms and definitions:

1.3.2 diagnostic message
a message belonging to an implementation-defined subset of the
implementation's output messages.



Brian
 
O

osmium

Default User said:
From the standard, under Terms and definitions:

1.3.2 diagnostic message
a message belonging to an implementation-defined subset of the
implementation's output messages.

There must be a word for that. You actually know *less* after reading the
definition than you did before you read it!
 
J

Jerry Coffin

[ ... ]
There must be a word for that. You actually know *less* after reading the
definition than you did before you read it!

I don't agree that's the case here, but where it is I
think "Schildtism" would be an appropriate term.
 
A

Alf P. Steinbach

* Pete Becker:
The Standard requires "a diagnostic." It does not specify the form or
the consequences of that diagnostic, and it does not distinguish between
a "warning" and an "error."

I didn't see this erronous nit-picking posting when you made it, but
I'll clear that up anyway.

The 1998 C++ standard contains 135 instances of "error" being used as a
synonym for "ill-formed".

I.e., you chose the wrong term to look up, you should have looked up
"ill-formed", not "diagnostic".

"Error" and "warning" are however not terms _defined_ by the standard.
They are terms used by actual compilers. "Error" means the program does
not compile, and "warning" means that at least that part of it compiles,
but with some probably dubious construct that may not do what you intended.

Just to repeat: the standard's official term corresponding to "error", a
program that does not compile, is not "diagnostic", it is "ill-formed"
 
A

Alf P. Steinbach

* Pete Becker:
It requires "a diagnostic." The standard doesn't talk about warnings and
errors.

It really does.

The 1998 C++ standard contains 135 instances of "error" being used as a
synonym for "ill-formed".

It also contains 1 usage of "warning", exemplifying that that is a term
it is assumed that readers of the standard should understand.
 
J

Jim Langston

Default User said:
From the standard, under Terms and definitions:

1.3.2 diagnostic message
a message belonging to an implementation-defined subset of the
implementation's output messages.

Umm.. if I'm reading htat right, it basically says that a diagnostic message
is an output message. Not exactly specific is it?
 
A

Alf P. Steinbach

* Jim Langston:
* "Default User":

Umm.. if I'm reading htat right, it basically says that a diagnostic message
is an output message. Not exactly specific is it?

"diagnostic" isn't the part being defined, you're assumed to understand
what "diagnostic" means. What's defined, in a badly worded way, is that
a compiler ("translator" in the standard's terminology) is allowed to
output other messages than those corresponding to "requires a
diagnostic", including non-diagnostic messages. If you go the route of
trying to find definitions of common-sense terms you won't find a
definition of "translator" either, although the term is used.
 
P

Pete Becker

Alf said:
Just to repeat: the standard's official term corresponding to "error", a
program that does not compile, is not "diagnostic", it is "ill-formed"

The standard does not require that anything not compile. An ill-formed
program requires a diagnostic. Nothing more.
 
P

Pete Becker

Alf said:
* Pete Becker:



It really does.

The 1998 C++ standard contains 135 instances of "error" being used as a
synonym for "ill-formed".

Nevertheless, it does not require "a warning" nor "an error" (not even
"a downright error") as used in the original message. Context matters.
It also contains 1 usage of "warning", exemplifying that that is a term
it is assumed that readers of the standard should understand.

The standard does not require "error" messages nor "warnings". It does
not require that anything not compile. The only requirement on
ill-formed programs is that the compiler issue a diagnostic.
 
P

Pete Becker

Jim said:
Umm.. if I'm reading htat right, it basically says that a diagnostic message
is an output message. Not exactly specific is it?

Nope. Could be text, could be beeps from the speaker, could be flashing
the screen. It's up to the implementation.
 
B

Bo Persson

Alf P. Steinbach said:
"Error" and "warning" are however not terms _defined_ by the
standard. They are terms used by actual compilers. "Error" means
the program does not compile, and "warning" means that at least that
part of it compiles, but with some probably dubious construct that
may not do what you intended.

There is no requirement to compile the program, it could be
interpreted. :)
Just to repeat: the standard's official term corresponding to
"error", a program that does not compile, is not "diagnostic", it is
"ill-formed"

Even if there is an "error" the translator can issue its diagnostic
(required), see that it was an obvious typo, and then continue with
the translation.


Bo Persson
 
D

Default User

osmium said:
There must be a word for that. You actually know less after reading
the definition than you did before you read it!

Actually, it lets you know you all you're going to be able to tell
about it. A diagnostic is an output message. It's
implementation-defined, which means that the implementation must
document the messages. That's all you can count on. There's no talk of
"warnings" or "errors", no indication that compilation must continue or
stop.




Brian
 
D

Default User

Jim said:
Umm.. if I'm reading htat right, it basically says that a diagnostic
message is an output message. Not exactly specific is it?

The key is that it is implementation-defined. The implementation is
required to document the diagostics. Of course, that doesn't mean that
they have to be meaningful (and we've all seen some pretty obscure or
misleading messages). Printing, "your code sucks and so do you" for
every diagnostic would be perfectly within the standard.



Brian
 
A

Alf P. Steinbach

* Pete Becker:
The standard does not require that anything not compile. An ill-formed
program requires a diagnostic. Nothing more.

That is correct, at last.
 
A

Alf P. Steinbach

* Bo Persson:
There is no requirement to compile the program, it could be
interpreted. :)

The standard simply assumes the reader is competent enough to understand
what's meant by e.g. "translation" and "error".

Even if there is an "error" the translator can issue its diagnostic
(required), see that it was an obvious typo, and then continue with
the translation.

Most compilers -- unfortunately -- do. If they hadn't they could
have been superfast. The idea of continuing is some idiocy from the
1950's that compiler writers haven't managed to rid themselves of.
 

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
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top