coleman@bert.dg.com (Kim Coleman) (03/29/89)
// Test that the compiler catches uninitialized references. Given that // references are conceptually an object rename, they must be initialized // to something (see Stroustrap, p. 56). At best, g++ gives a warning, // at worst, it says nothing at all. void some_function() { int& a_ref; // g++ gives a warning } class erroneous { int& a_ref; // g++ says nothing }; Personally, I think both these cases should be an error, but a warning is better than nothing. Sorry if this has been posted before. --------------------------- Kim Coleman Data General Corp., Research Triangle Park, NC {the world}!mcnc!rti!dg-rtp!coleman
tiemann@YAHI.STANFORD.EDU (Michael Tiemann) (04/08/89)
Date: 28 Mar 89 17:47:34 GMT From: rti!xyzzy!bert!coleman@mcnc.org (Kim Coleman) Organization: Data General Corporation, Research Triangle Park, NC. Sender: bug-g++-request@prep.ai.mit.edu // Test that the compiler catches uninitialized references. Given that // references are conceptually an object rename, they must be initialized // to something (see Stroustrap, p. 56). At best, g++ gives a warning, // at worst, it says nothing at all. void some_function() { int& a_ref; // g++ gives a warning } It should give an error here. class erroneous { int& a_ref; // g++ says nothing }; This is no cause for alarm. If you try to use this class without specifying an initialzer for the reference, they you should get an error. But here is how you won't run aground: int savior; erroneous not_so_erroneous = { savior }; In this case, savior is specified as an initializer for the reference in not_so_erroneous. Personally, I think both these cases should be an error, but a warning is better than nothing. Sorry if this has been posted before. Error for references are better than warnings, but the compiler should not be too eager to slap you. By the way, in working out this example, I found that it does not work if not_so_erroneous is in global scope. I have therefore fixed it for the next release. --------------------------- Kim Coleman Data General Corp., Research Triangle Park, NC {the world}!mcnc!rti!dg-rtp!coleman