diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2018-01-17 20:28:47 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2018-01-17 20:28:47 +0000 |
commit | 9638f320ec3f396f57df753a70785a0390d40f3e (patch) | |
tree | ed0135709c9dceaaf7b59ef3148f972459c12f4f /gcc | |
parent | 95f94b38bbc1f65ddb5287b8fe1e357bfba36aef (diff) | |
download | gcc-9638f320ec3f396f57df753a70785a0390d40f3e.zip gcc-9638f320ec3f396f57df753a70785a0390d40f3e.tar.gz gcc-9638f320ec3f396f57df753a70785a0390d40f3e.tar.bz2 |
re PR c++/81054 (ICE with volatile variable in constexpr function)
/cp
2018-01-17 Paolo Carlini <paolo.carlini@oracle.com>
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 <paolo.carlini@oracle.com>
PR c++/81054
* g++.dg/cpp0x/constexpr-ice19.C: New.
From-SVN: r256816
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 6 | ||||
-rw-r--r-- | gcc/cp/decl.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C | 13 |
4 files changed, 30 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 71fa358..17b4192 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-01-17 Paolo Carlini <paolo.carlini@oracle.com> + + 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 <nathan@acm.org> PR c++/83287 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b216e09..8984613 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 %<constexpr%> 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 %<constexpr%> " "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 ee469d3..148afa6 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 0000000..7066eab --- /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" } +}; |