8sa1-gcc/gcc/testsuite/g++.dg/cpp2a/constexpr-try3.C
Jakub Jelinek 1259cb6d00 Implement P1002R1, Try-catch blocks in constexpr functions PR c++/89513
Implement P1002R1, Try-catch blocks in constexpr functions
	PR c++/89513
	* parser.c (cp_parser_ctor_initializer_opt_and_function_body):
	Diagnose constexpr ctor or function with function-try-block with
	pedwarn for c++17 and earlier.  Formatting fix.
	(cp_parser_try_block): Use pedwarn instead of error and only for
	c++17 and earlier when try block appears in constexpr function.
	* constexpr.c (build_constexpr_constructor_member_initializers):
	Handle TRY_BLOCK here instead of erroring on it.

	* g++.dg/cpp2a/constexpr-try1.C: New test.
	* g++.dg/cpp2a/constexpr-try2.C: New test.
	* g++.dg/cpp2a/constexpr-try3.C: New test.
	* g++.dg/cpp2a/constexpr-try4.C: New test.
	* g++.dg/cpp2a/constexpr-try5.C: New test.
	* g++.dg/cpp0x/constexpr-ctor10.C: Don't expect error for C++2a.

From-SVN: r269314
2019-03-01 15:20:03 +01:00

45 lines
1.6 KiB
C

// PR c++/89513
// { dg-do compile { target c++11 } }
// { dg-options "" }
constexpr bool foo ()
try { // { dg-warning "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
return true;
} catch (...) {
return false;
} // { dg-error "body of 'constexpr' function" "" { target c++11_only } }
constexpr bool bar ()
try { // { dg-warning "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
try { // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
return true;
} catch (int) {
return false;
}
} catch (...) {
return false;
} // { dg-error "not a return-statement" "" { target c++11_only } }
constexpr bool baz ()
{
try { return true; } catch (...) { return false; } // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
} // { dg-error "not a return-statement" "" { target c++11_only } }
struct S {
constexpr S () try : m (1) // { dg-warning "function-try-block body of 'constexpr' constructor only available with" "" { target c++17_down } }
{
try { // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
} catch (int) {
}
} catch (...) { // { dg-error "'constexpr' constructor does not have empty body" "" { target c++11_only } }
}
int m;
};
struct T {
constexpr T ()
try { // { dg-warning "function-try-block body of 'constexpr' constructor only available with" "" { target c++17_down } }
} catch (...) {
}
};