From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,3bb0dcf4dc92e48d X-Google-Attributes: gid109fba,public X-Google-Thread: fee84,3bb0dcf4dc92e48d X-Google-Attributes: gidfee84,public From: Marc Roussel Subject: Mysterious DEC OSF C++ compiler warning Date: 1995/12/18 Message-ID: <4b4rog$m80@holly.cc.uleth.ca>#1/1 X-Deja-AN: 122288004 content-type: text/plain; charset=us-ascii organization: Department of Chemistry, University of Lethbridge x-url: news:comp.lang.c++ mime-version: 1.0 newsgroups: comp.lang.c++,comp.unix.osf.osf1 x-mailer: Mozilla 1.1N (X11; I; OSF1 V3.2 alpha) Here's a simple program for which the DEC OSF C++ compiler generates a (to me) mysterious warning: // foo.h: class junk { double a; public: junk(void) {}; junk(double x) { a = x;}; junk & operator = (junk & x) { a = x.a; return(*this);}; }; // foo.c #include #include #include "foo.h" main() { junk x; x = junk(2); } The warning is foo.c:10: warning: In this statement, the initialization of a non-const reference requires a temporary for "junk(2)". Programs which generate this warning nevertheless appear to execute correctly. Is the DEC compiler getting excited about nothing? Is it warning me about nonportable usage? Bad style? What's the scoop? If I'm doing something wrong, is there a reasonably easy workaround? Note that the line which reads "x=junk(2)" can be replaced with "x=2" and still generates a similar warning. Finally, I should mention that code like this generates no warnings with the somewhat old Borland compiler on my home machine. Thanks in advance for any help you can offer. -- Marc R. Roussel (roussel@henri.chem.uleth.ca) Department of Chemistry University of Lethbridge