131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh// PR c++/7050
231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh// { dg-do run }
331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsiehextern "C" void abort(void);
531ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
631ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh#define CI(stmt) try { stmt; abort(); } catch (int) { }
731ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
831ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsiehstruct has_destructor
931ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh{
1031ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    ~has_destructor() { }
1131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh};
1231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
1331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsiehstruct no_destructor
1431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh{
1531ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh};
1631ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
1731ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsiehint PI(int& i) { return i++; }
1831ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
1931ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsiehint main(int argc, char *argv[])
2031ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh{
2131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (argc+1 ? has_destructor() : throw 0);
2231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI((argc+1 ? throw 0 : has_destructor()));
2331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI((0 ? has_destructor() : throw 0));
2431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI((1 ? throw 0 : has_destructor()));
2531ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (0 ? throw 0 : has_destructor());
2631ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (1 ? has_destructor() : throw 0);
2731ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
2831ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (argc+1 ? no_destructor() : throw 0);
2931ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI((argc+1 ? throw 0 : no_destructor()));
3031ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI((0 ? no_destructor() : throw 0));
3131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI((1 ? throw 0 : no_destructor()));
3231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (0 ? throw 0 : no_destructor());
3331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (1 ? no_destructor() : throw 0);
3431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
3531ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    int i = 1;
3631ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI(throw PI(i));
3731ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 2) abort();
3831ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
3931ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (1 ? 0 : throw PI(i));
4031ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 2) abort();
4131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
4231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI(0 ? 0 : throw PI(i));
4331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 3) abort();
4431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
4531ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI(0 ? has_destructor() : throw PI(i));
4631ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 4) abort();
4731ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (argc+1 ? has_destructor() : throw PI(i));
4831ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 4) abort();
4931ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
5031ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    i = 1;
5131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI(throw i++);
5231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 2) abort();
5331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
5431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (1 ? 0 : throw i++);
5531ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 2) abort();
5631ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
5731ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI(0 ? 0 : throw i++);
5831ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 3) abort();
5931ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh
6031ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    CI(0 ? has_destructor() : throw i++);
6131ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 4) abort();
6231ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    (argc+1 ? has_destructor() : throw i++);
6331ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh    if (i != 4) abort();
6431ad4de047c50cddfc3072be3a82232c53f1ca2dAndrew Hsieh}
65