This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/33012] ICE on throwing copy of object returned by reference from method with traits-deduced return-type



------- Comment #1 from raymond at corvil dot com  2007-08-07 17:59 -------
I have been able to reproduce the same ICE in 3.4.2,

    gcc version 3.4.2 20040827 (prerelease) [FreeBSD]

but not in 2.95.4 or 4.1.2:

    gcc version 2.95.4 20020320 [FreeBSD]
    gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)


I originally found the ICE in some code that was throwing a copy of an object
in a std::vector on the stack.  By playing around with the test code I posted,
I found that it seems to trigger only when the following three conditions occur
together:

* the copy is directly thrown, and not when the a copy is declared on the stack
and then thrown;
* the method that provides the reference to be copied has a return-type deduced
from a traits template;
* the class of the object being thrown does not provide a copy-constructor.

I've tried to illustrate in the full test case that, if any one of these
conditions is false, then the ICE doesn't happen.


The following shorter test-case also triggers the error.  I know it includes a
standard header, and I haven't provided pre-processed sources for this, but
it's just for illustration purposes.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include <vector>

/*
 * inner() throws a copy of an object contained in a vector.
 * It's templated to show what happens with different _Types.
 */

template<typename _Type>
void    inner()
{
        typename std::vector<_Type> vector(1);
        throw _Type(*vector.begin());
}


struct Generated { };

struct Manual {
        Manual() { }
        Manual(const Manual&) { }
};


void    outer()
{
// No problems when the class has a hand-written copy-constructor:
        inner<Manual>();

// ICE when the class has a compiler-supplied copy-constructor:
        inner<Generated>();
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33012


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]