From 9638f320ec3f396f57df753a70785a0390d40f3e Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 17 Jan 2018 20:28:47 +0000 Subject: [PATCH] re PR c++/81054 (ICE with volatile variable in constexpr function) /cp 2018-01-17 Paolo Carlini PR c++/81054 * constexpr.c (ensure_literal_type_for_constexpr_object): Return error_mark_node when we give an error. * decl.c (cp_finish_decl): Use the latter. /testsuite 2018-01-17 Paolo Carlini PR c++/81054 * g++.dg/cpp0x/constexpr-ice19.C: New. From-SVN: r256816 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/constexpr.c | 6 ++++-- gcc/cp/decl.c | 8 ++++++-- gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C | 13 +++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 71fa358f5f8..17b41921db9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-01-17 Paolo Carlini + + PR c++/81054 + * constexpr.c (ensure_literal_type_for_constexpr_object): Return + error_mark_node when we give an error. + * decl.c (cp_finish_decl): Use the latter. + 2018-01-17 Nathan Sidwell PR c++/83287 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b216e090b45..8984613aa41 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -75,7 +75,8 @@ literal_type_p (tree t) } /* If DECL is a variable declared `constexpr', require its type - be literal. Return the DECL if OK, otherwise NULL. */ + be literal. Return error_mark_node if we give an error, the + DECL otherwise. */ tree ensure_literal_type_for_constexpr_object (tree decl) @@ -97,6 +98,7 @@ ensure_literal_type_for_constexpr_object (tree decl) error ("the type %qT of % variable %qD " "is not literal", type, decl); explain_non_literal_class (type); + decl = error_mark_node; } else { @@ -105,10 +107,10 @@ ensure_literal_type_for_constexpr_object (tree decl) error ("variable %qD of non-literal type %qT in % " "function", decl, type); explain_non_literal_class (type); + decl = error_mark_node; } cp_function_chain->invalid_constexpr = true; } - return NULL; } } return decl; diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index ee469d35137..148afa6c9ac 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6810,8 +6810,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } - if (!ensure_literal_type_for_constexpr_object (decl)) - DECL_DECLARED_CONSTEXPR_P (decl) = 0; + if (ensure_literal_type_for_constexpr_object (decl) + == error_mark_node) + { + DECL_DECLARED_CONSTEXPR_P (decl) = 0; + return; + } if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C new file mode 100644 index 00000000000..7066eabdfc7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C @@ -0,0 +1,13 @@ +// PR c++/81054 +// { dg-do compile { target c++11 } } + +struct A +{ + volatile int i; + constexpr A() : i() {} +}; + +struct B +{ + static constexpr A a {}; // { dg-error "not literal" } +}; -- 2.30.2