473,698 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

This is ridiculous!

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

void FunctionThatMod ifies(std::stri ng &a)
{
a = "You've been modified.";
}
int main()
{
std::string const a("Untouchable. ");
std::string &b = a; //Actually compiles with error!
FunctionThatMod ifies(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
Mar 4 '06
50 2715
Alf P. Steinbach wrote:
With "error" meaning "ill-formed", the meaning of "warning" is easy to > deduce, given the definition of "diagnostic ": it is the set of other possible diagnostics. Current compilers label them as warnings.


Remarkable. You've turned no normative words in the standard into a
requirement that no compiler conforms to.

Once again, for the benefit of anyone who may still be reading this
well-named thread: the C++ Standard requires "a diagnostic" for an
ill-formed program. That's all.

--

Pete Becker
Roundhouse Consulting, Ltd.
Mar 7 '06 #31
Pete Becker wrote:

Once again, for the benefit of anyone who may still be reading this
well-named thread: the C++ Standard requires "a diagnostic" for an
ill-formed program. That's all.


Whoops, it requires less than that. It requires "a diagnostic message"
for a program that violates any diagnosable rule. Some of the rule whose
violation makes a program ill-formed are not diagnosable rules.

--

Pete Becker
Roundhouse Consulting, Ltd.
Mar 7 '06 #32
* Pete Becker:
Alf P. Steinbach wrote:
> With "error" meaning "ill-formed", the meaning of "warning" is easy to > deduce, given the definition of "diagnostic ": it is the set of other
> possible diagnostics. Current compilers label them as warnings.


Remarkable. You've turned no normative words in the standard into a
requirement that no compiler conforms to.


That's incorrect in several ways.

Including that your statement is at odds with reality: most modern
compilers do issue compilation errors for the OP's construct.

But the most basic error in your statement is the flawed deduction that
a compiler that compiles the OP's source code can be conforming, in any
practical sense.

A compiler that compiles that is not conforming in any practical sense.

Are you still going on about what you can deduce from literal
definitions, ignoring reality and context? As should be clear by now,
that's /nothing/. The C++ standard is not a completely formal document,
nor could it be, and so via the literal interpretation rule you end up
with undefined words (like "diagnostic "), always; moreover, with the
literal interpretation the standard is formally inconsistent in several
places, and nothing (or anything at all, depending on your preferences)
can be deduced from inconsistency, which is a well-known fallacy.

Once again, for the benefit of anyone who may still be reading this
well-named thread: the C++ Standard requires "a diagnostic" for an
ill-formed program. That's all.


Yes. And the C++ standard differentiates between different kinds of
diagnostics. And includes at least one example, shown earlier, where
this particular kind of ill-formedness is labeled an "error".

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 7 '06 #33
Alf P. Steinbach wrote:

But the most basic error in your statement is the flawed deduction that
a compiler that compiles the OP's source code can be conforming, in any
practical sense.


There's no deduction involved. The standard requires the implementation
to issue a diagnostic. It did.

--

Pete Becker
Roundhouse Consulting, Ltd.
Mar 7 '06 #34
In article <47************ @individual.net >,
al***@start.no says...

[ ... ]
By now you should have understood what "error" means, as the word is
used in the standard and by the OP.

But I'll explain it once more: it means "ill-formed".


Sorry Alf, but here you're just plain wrong.

The standard (at least generally) uses phrasing like "it
is an error if ..." to mean something like "code is ill
formed if ...", that much is true.

The OP, in strong contrast, was clearly using "error" to
mean an error message. Specifically, that the code in
question would NOT be successfully translated.

The standard does not require any such thing under any
circumstances.

The standard requires the implementation to issue a
diagnostic message if any diagnosable rule is violated.
The standard defines the diagnosable rules, and requires
the implementation to define what it considers a
diagnostic.

The marketplace, not the standard, decides anything
beyond that. In particular, most compilers (including the
OP's, apparently) issue a warning for his code. Most
compilers also allow you to elevate warnings to be
treated as error messages (i.e. that code that produces
that message will not be successfully translated). Some
do so only on a blanket basis (i.e. all warnings are
treated as errors) while others allow more selectivity in
doing so -- i.e. you have greater granularity in choosing
which warnings will be treated as errors.

The details of that, however, are clearly specific to the
compiler and off-topic here though, because they have to
do with how you run the compiler, not with the language.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mar 7 '06 #35
* Jerry Coffin:
In article <47************ @individual.net >,
al***@start.no says...

[ ... ]
By now you should have understood what "error" means, as the word is
used in the standard and by the OP.

But I'll explain it once more: it means "ill-formed".


Sorry Alf, but here you're just plain wrong.

The standard (at least generally) uses phrasing like "it
is an error if ..." to mean something like "code is ill
formed if ...", that much is true.

The OP, in strong contrast, was clearly using "error" to
mean an error message. Specifically, that the code in
question would NOT be successfully translated.

The standard does not require any such thing under any
circumstances.

The standard requires the implementation to issue a
diagnostic message if any diagnosable rule is violated.
The standard defines the diagnosable rules, and requires
the implementation to define what it considers a
diagnostic.

The marketplace, not the standard, decides anything
beyond that. In particular, most compilers (including the
OP's, apparently) issue a warning for his code. Most
compilers also allow you to elevate warnings to be
treated as error messages (i.e. that code that produces
that message will not be successfully translated). Some
do so only on a blanket basis (i.e. all warnings are
treated as errors) while others allow more selectivity in
doing so -- i.e. you have greater granularity in choosing
which warnings will be treated as errors.

The details of that, however, are clearly specific to the
compiler and off-topic here though, because they have to
do with how you run the compiler, not with the language.


Apart from the phrasing "most compilers" (I really don't think that's
correct) the above sounds eminently reasonable.

It makes it seem as if it's just a matter of degree, outside the scope
of the standard; warning, error, one can be treated as the other,
they're all just diagnostics.

Until you consider the following seemingly conforming C++
implementation, which you can implement in a few minutes time using a
script language. It is a C++ implementation, let's call it OhLaLa
because it is 100% conforming, perfect!, that takes a C++ source file,
or fileset (translation unit that comprises a program), and executes it,
all according to the C++ standard's rules. It's done as follows:

1) If the source code compiles with no errors (output suppressed)
using a compiler B that compiles and only compiles well-formed
source code without errors, delete all result files and issue a
diagnostic "error: out of memory, sorry". This per the "available
resources" clause in §1.4/2 of the standard.

2) Otherwise, if B fails to compile the source code, issue a
diagnostic "warning: extension used", and run a program that spams
all heads of state in Europe (it will always be the same program)
and calls the OS' process exit function; which program, let's call
it S, constitutes the effect of the provided C++ source code. The
language extension is simply that any compilation failure using B
means that the effect of S should be prepended to the effect of the
code minimally adjusted, in some sense, so that it would compile
using B. This is per §1.4/8, which allows extensions that do not
alter the behavior of well-formed programs.

Effectively the OhLaLa C++ implementation is, as I see it, a 100%
conforming C++ implementation when all that's required is what a literal
reading of the standard imposes on a conforming implementation.

However, _I_ wouldn't call OhLaLa a conforming implementation. I would
not even call it a C++ implementation, since the C++ source code does
not influence any effect of submitting the source code to OhLaLa, other
than turning off the single pre-defined effect (and we could, if not for
dramatic impact, turn off that effect so that the C++ source code would
influence absolutely nothing). So as I see it there's something missing
from the literal interpretation picture, and it even begins to seem a
teeny tiny bit unreasonable, don't you think?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 8 '06 #36
In article <47************ @individual.net >,
al***@start.no says...

[ ... ]
Apart from the phrasing "most compilers" (I really don't think that's
correct) the above sounds eminently reasonable.
Would you settle for "many compilers" instead? I haven't
tried to do a survey (especially in the embedded space
and such) so maybe I'm just deceived by the compilers I
happen to use, and falsely assume most of the others have
similar capabilities.

[ ... ]
Effectively the OhLaLa C++ implementation is, as I see it, a 100%
conforming C++ implementation when all that's required is what a literal
reading of the standard imposes on a conforming implementation.
In terms purely of conforming with the standard, I think
that's probably correct.
However, _I_ wouldn't call OhLaLa a conforming implementation. I would
not even call it a C++ implementation, since the C++ source code does
not influence any effect of submitting the source code to OhLaLa, other
than turning off the single pre-defined effect (and we could, if not for
dramatic impact, turn off that effect so that the C++ source code would
influence absolutely nothing). So as I see it there's something missing
from the literal interpretation picture, and it even begins to seem a
teeny tiny bit unreasonable, don't you think?


Actually, I think you could leave out most (all?) of
section 2 of your description of OhLaLa and still have a
conforming implementation of C++.

You seem to want the standard to require enough that a
conforming implementation at least stands some chance of
being useful. At one time I'd have agreed vehemently. I
can still sympathize, but can't really agree anymore. The
reason is simple: such rules would take considerable time
and effort to make, but I seriously doubt they'd make any
real difference. Right now Comeau is the only C++
compiler that makes a serious attempt at full conformance
(though rumor has it that Intel unofficially supports
export as well) At the same time, most compilers go well
beyond the requirements of the standard in terms of
attempting to provide useful warnings, error messages,
etc.

Given that I think it would take a lot of time and effort
and provide no real benefit, I think I'd rather see time
spent on endeavors I think would be more fruitful.

I don't believe, however, that just because the standard
makes no meaningful requirements in a given area that we
can treat it as requiring things that just aren't there.

If you're really convinced that the standard _should_
have stronger requirements in this area, the obvious
thing to do would be to write up a proposal, and submit
it to the committee. It wouldn't be a new language
feature, so I believe the committee would still accept it
as a proposal for the next version of the standard. I
really think it's a waste of time though -- there are
enough good compilers being given away freely today that
I really don't think stopping a useless one from being
able to claim it's conforming would really accomplish
much.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mar 8 '06 #37
* Jerry Coffin:
In article <47************ @individual.net >,
al***@start.no says...

[ ... ]
Apart from the phrasing "most compilers" (I really don't think that's
correct) the above sounds eminently reasonable.
Would you settle for "many compilers" instead? I haven't
tried to do a survey (especially in the embedded space
and such) so maybe I'm just deceived by the compilers I
happen to use, and falsely assume most of the others have
similar capabilities.

[ ... ]
Effectively the OhLaLa C++ implementation is, as I see it, a 100%
conforming C++ implementation when all that's required is what a literal
reading of the standard imposes on a conforming implementation.


In terms purely of conforming with the standard, I think
that's probably correct.
However, _I_ wouldn't call OhLaLa a conforming implementation. I would
not even call it a C++ implementation, since the C++ source code does
not influence any effect of submitting the source code to OhLaLa, other
than turning off the single pre-defined effect (and we could, if not for
dramatic impact, turn off that effect so that the C++ source code would
influence absolutely nothing). So as I see it there's something missing
from the literal interpretation picture, and it even begins to seem a
teeny tiny bit unreasonable, don't you think?


Actually, I think you could leave out most (all?) of
section 2 of your description of OhLaLa and still have a
conforming implementation of C++.

You seem to want the standard to require enough that a
conforming implementation at least stands some chance of
being useful.


Well, it's much stronger than that: wherever the standard does not
explictly require anything at all (and I mean a non-requirement, the
non-requirement of /anything/, as with the 100% conforming OhLaLa "C++
implementation" which isn't a C++ implementation at all), there is IMO
an implicit requirement. OhLaLa, while being literally formally
correct, would not pass any C++ conformance test, I think. That's
because such tests reflect the implicit requirement of usefullness,
which out of any context might seem wooly, but which constrains things.
[snip] I don't believe, however, that just because the standard
makes no meaningful requirements in a given area that we
can treat it as requiring things that just aren't there.
Here's what I think is in the standard regarding the OP's question.
First, that as standard C++ this ill-formed code. Second, that it's
ill-formed code that requires a diagnostic. And third, implicitly, that
that diagnostic should make it clear that the code is ill-formed as
standard C++, which AFAIK is the case for all diagnostics that the
standard requires, there being no requirement (AFAIK) of diagnostics for
well-formed code.

The third, implicit requirement is, as I see it, the only way to make
sense of the standard's definition of "diagnostic ", which just makes the
diagnostics a subset of the implementation' s "output messages".

Current compilers and compilers back to the 1950s or thereabouts make it
clear that an output message refers to ill-formed code by labeling the
message as an "error", and/or by including phrases such as "language
extension", and make clear that messages that don't refer to ill-formed
code are such by labeling them as "warnings" (w/o "language extension").

The effective requirement on such a compiler is then to produce an
"error" message, unless a language extension is involved, in which case
the message might include the phrase "language extension" or the like.

If you're really convinced that the standard _should_
have stronger requirements in this area, the obvious
thing to do would be to write up a proposal, and submit
it to the committee.


No, as I see it the requirement is already there. What's not there is
how a compiler should distinguish output messages that refer to
ill-formed code, i.e. standards violations for pure C++. I don't think
that how-to belongs in the standard, but for a compiler that has
mutually exclusive and exhaustive subsets X and Y of output messages, Y
being the subset distinguished as denoting ill-formed program text, the
requirement in the OP's case is as I see that the compiler issues a Y
message; which with a conventional warning/error-compiler such as the
OP's compiler means an error message (subject to the little caveat about
language extensions I mentioned above -- with such a big sub-thread
evolving I don't save any keystrokes by omitting it!).

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 8 '06 #38
* Alf P. Steinbach:
Current compilers and compilers back to the 1950s or thereabouts


Before some nit-picker steps in here: I'm not referring to only C++
compilers, but to compilers back to early Fortran and Cobol.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 8 '06 #39
Jerry Coffin wrote:

The standard (at least generally) uses phrasing like "it
is an error if ..." to mean something like "code is ill
formed if ...", that much is true.


And, specifically, the standard never uses the word "error" in running
text to refer to a violation of a syntactic rule or semantic constraint.
What it does do is follow Stroustrup's pattern of giving code examples
with comments:

some_constuct; // error: explanation
some_other_cons tuct; // OK: explanation

--

Pete Becker
Roundhouse Consulting, Ltd.
Mar 8 '06 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
7753
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another GUI toolkit that is cross-platform for Python, and am leaning toward PyQt (PyGTK is kind of dull looking in comparison). Unfortunately, although TrollTech says Qt is cross-platform, its license strategy has me a bit confused. So here is to...
52
6308
by: Vladimir Grul | last post by:
Hello, I have a class member function declared as class some_class { .... virtual int call(void); }; Can I use this-> inside the function body?
4
2159
by: Schraalhans Keukenmeester | last post by:
I have no clue why below code (found it somewhere and altered it a wee bit to my needs) will run without problem in both IE and Mozilla FireFox 1.0 but in the latter it takes up close to 100% cpu. It does check for type of browser, and indeed all works fine apart from that ridiculous amount of cpu taken. If you want to see if it does so in your firefox/xp too, it's embedded in my homepage (www.westerterp.com) Can anyone explain why...
23
355
by: Darklight | last post by:
Question taken from a book Write a function that accepts two strings. Use the malloc() function to allocate enough memory to hold two strings after they have been concatenated(linked). Return a pointer to this new string. /* STRCAT1.C PROGRAM TO LINK TWO STRINGS TOGETHER */ #include<stdio.h> #include<string.h> #include<stdlib.h>
6
1443
by: RichG | last post by:
Does anyone remember this: Set datapath to "c:\somewhere" dNetUse "SomeTable" do some db work I asked the question a couple of days ago about how to attach a recordset or some form of data to a datagrid. I was using DAO. The lack of responses seemed to indicate that the question was out of the range of an answer. So I started looking around to find out what does this datagrid want that the datagrid in VB5 did not need. It looked...
171
4875
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
30
508
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
26
2839
by: Tomás Ó hÉilidhe | last post by:
Has anyone here got access to a ridiculous computer? Something like: CHAR_BIT == 9 PADDING_BITS(int) != 0 NUMBER_SYSTEM == SIGN_MAGNITUDE Null pointer bit pattern == All ones I'm writing some fully-portable code and would love to actually compile it for, and test it on, a very strange machine :-D
40
1986
by: Dave | last post by:
Hello, I'm teaching myself C by working my way through Steve Summit's tutorial (http://www.eskimo.com/~scs/cclass/cclass.html). In one of the questions (assignment 6, exercise 7), you have to write a function to read lines of arbitrary length from the command line, using malloc() and realloc() to allocate the necessary memory to hold the lines. I came up with this: char *getline(char *line) {
0
8672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9155
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9018
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8858
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.