On Tue, Jun 12, 2007 at 09:27:34AM -0400, me22 wrote: > On 12/06/07, Arend-Jan Wijtzes <ajwytzes@xxxxxxxxxxxx> wrote: > >However in this case: > > > >[...] > > > >No warning is issued. I tried this with gcc-3.3.6 and gcc-4.1.0. > >Is there any way to make the compiler warn about this mistake? > > > >P.S. If you're wondering what's the point if you're not going to use x, > >I use wrapper classes and the stack unwinding mechanism to auto-release > >locks or cleanup other resources. > > > I think you've probably found your own answer. Constructors and > destructors can have arbitrary side effects, so GCC might just not > try. The inliner might be able to reduce it to something that it > could figure out, but by then the variable information might be lost > (I don't know enough about internals to know). > > And if you're using RAII classes for things like scoped locks, they > certainly have side effects, so the statement does have an effect. > For anything without side effects, you'll need to use it at some > point, where you'll get an undeclared identifier warning. > > ~ Scott > > P.S. I think that's construction of a temporary, not a cast, technically. Hi Scott, Yes you are right, it's not a cast. And the 'statement without effect' warning does not apply. But what puzzles me is that I can actually declare a nameless object like that. For example the analogy with int would be: int main() { int; } which gives the error: "error: declaration does not declare anything". Now I'm not advocating that this should be an error for classes, but it would be nice if there was some mechanism to warn about this. How likely is it that an author actually intends to create an object and immediately destroy it again in one line of code, without doing anything with it? Regards, Arend-Jan