Re: GCC issue: No error on in-class initialization of non-integral static const variables
Re: GCC issue: No error on in-class initialization of non-integral static const variables
- Subject: Re: GCC issue: No error on in-class initialization of non-integral static const variables
- From: Zachary Pincus <email@hidden>
- Date: Mon, 11 Jul 2005 00:14:08 -0700
Good to know that GCC has that error. Nevertheless, to be a bit
(ahem) pedantic myself, I would posit that something which (a) used
to work in a previous version of GCC, and (b) causes GCC not to emit
a symbol for something which it nevertheless permits to be referenced
in the code, should raise an error *by default.*
Perhaps that error didn't got moved from "pedantic" to "default" when
GCC started enforcing the no-non-integral-in-class-static-const-
initializers rule? I simply can't imagine a case where someone
wouldn't want to be warned that a variable referenced in their code
is not actually in the symbol table anywhere. (I don't count the link
error, or worse, the run-time undefined symbol error, as adequate
since they are much more cryptic, especially in the name-mangled
latter case. The GCC error, after all, explains the cause of the
problem, not just the symptom.)
Of course, argument from failure of imagination is not particularly
valuable. Nevertheless, I still claim that this is incorrect behavior
(though perhaps not even a "bug" much less a bug) on GCC's part.
Especially since all other errors about in class initializers (e.g.
attempting to initialize a non-static and/or non-const value) are
error by default. If the problem is in main-line GCC I'll file a bug
there. Otherwise, I'll file one with Apple.
Zach Pincus
Program in Biomedical Informatics and Department of Biochemistry
Stanford University School of Medicine
On Jul 10, 2005, at 10:46 PM, Justin C. Walker wrote:
On Jul 10, 2005, at 22:35 , Zachary Pincus wrote:
According to the C++ standard (I think! Correct if wrong.), in-
class initialization of static const integral types is permitted.
That is:
struct Foo {
static const int bar = 10;
};
is ok, whereas if 'bar' were not an integral type (enum, int,
etc.) but a float or pointer or so forth, it would not be permitted.
Now, previous versions of GCC didn't mind when 'bar' was a float,
etc. But with GCC's push to better standards compliance, this is
no longer allowed.
The only problem is that GCC doesn't produce an error about this.
It's only at link-time (or worse, run-time, if '-undefined
dynamic_lookup' is used) that this causes an 'undefined symbol'
error.
If you use "-pedantic", it will tell you what you want to know :-}
$ c++ -pedantic bif.cc
bif.cc:2: error: ISO C++ forbids initialization of member constant
'bar' of non-integral type 'const float'
Regards,
Justin
--
Justin C. Walker, Curmudgeon-at-Large
/~\ The ASCII
\ / Ribbon Campaign
X Help Cure HTML Email
/ \
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40stanford.edu
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden