throwdeep_hierarchy();// Ok, multiple levels of inheritance
}catch(deep_hierarchy&e){// Ok
}
throwdeep_hierarchy();// Ok
try{
throwterrible_idea();// Ok, but multiple inheritance isn't clean
}catch(std::exception&e){// Can be caught as std::exception, even with multiple inheritance
}
throwterrible_idea();// Ok, but multiple inheritance
}
// Templated function that throws exception based on template type
template<typenameT>
voidThrowException(){throwT();}
// CHECK-MESSAGES: [[@LINE-1]]:31: warning: throwing an exception whose type 'bad_generic_exception<int>' is not derived from 'std::exception'
// CHECK-MESSAGES: 120:1: note: type defined here
// CHECK-MESSAGES: [[@LINE-3]]:31: warning: throwing an exception whose type 'bad_generic_exception<std::exception>' is not derived from 'std::exception'
// CHECK-MESSAGES: 120:1: note: type defined here
// CHECK-MESSAGES: [[@LINE-5]]:31: warning: throwing an exception whose type 'exotic_exception<non_derived_exception>' is not derived from 'std::exception'
// CHECK-MESSAGES: 123:1: note: type defined here
// CHECK-MESSAGES: [[@LINE-7]]:31: warning: throwing an exception whose type 'int' is not derived from 'std::exception'
// CHECK-MESSAGES: [[@LINE-8]]:31: warning: throwing an exception whose type 'non_derived_exception' is not derived from 'std::exception'
// CHECK MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type 'int' is not derived from 'std::exception'
THROW_EXCEPTION(non_derived_exception);
// CHECK MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type 'non_derived_exception' is not derived from 'std::exception'
// CHECK MESSAGES: 9:1: note: type defined here
THROW_EXCEPTION(std::exception);// Ok
THROW_EXCEPTION(derived_exception);// Ok
THROW_EXCEPTION(deep_hierarchy);// Ok
THROW_BAD_EXCEPTION;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type 'int' is not derived from 'std::exception'
// CHECK-MESSAGES: [[@LINE-25]]:35: note: expanded from macro 'THROW_BAD_EXCEPTION'
THROW_GOOD_EXCEPTION;
THROW_DERIVED_EXCEPTION;
throwgeneric_exception<int>();// Ok,
THROW_EXCEPTION(generic_exception<float>);// Ok
throwbad_generic_exception<int>();
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'bad_generic_exception<int>' is not derived from 'std::exception'
throwbad_generic_exception<std::exception>();
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'bad_generic_exception<std::exception>' is not derived from 'std::exception'
THROW_EXCEPTION(bad_generic_exception<int>);
// CHECK MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type 'bad_generic_exception<int>' is not derived from 'std::exception'
// CHECK MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type 'bad_generic_exception<std::exception>' is not derived from 'std::exception'
throwexotic_exception<non_derived_exception>();
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'exotic_exception<non_derived_exception>' is not derived from 'std::exception'
// CHECK MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type 'exotic_exception<non_derived_exception>' is not derived from 'std::exception'
throwexotic_exception<derived_exception>();// Ok
THROW_EXCEPTION(exotic_exception<derived_exception>);// Ok
}
// Test for typedefed exception types
typedefintTypedefedBad;
typedefderived_exceptionTypedefedGood;
usingUsingBad=int;
usingUsingGood=deep_hierarchy;
voidtypedefed(){
throwTypedefedBad();
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'TypedefedBad' (aka 'int') is not derived from 'std::exception'
// CHECK-MESSAGES: 164:1: note: type defined here
throwTypedefedGood();// Ok
throwUsingBad();
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'UsingBad' (aka 'int') is not derived from 'std::exception'