diff options
author | Jason Merrill <jason@redhat.com> | 2010-11-01 21:31:31 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2010-11-01 21:31:31 -0400 |
commit | ddbbc9a109f3d8b91f5ba43a4b0d933d048a3b0f (patch) | |
tree | 82ebd2f5b98a6666636b46ec9382fdf7d0b34886 /gcc/cp | |
parent | fa2200cbb1ef5a6a7bdb9a5ba708c7400eb6b404 (diff) | |
download | gcc-ddbbc9a109f3d8b91f5ba43a4b0d933d048a3b0f.zip gcc-ddbbc9a109f3d8b91f5ba43a4b0d933d048a3b0f.tar.gz gcc-ddbbc9a109f3d8b91f5ba43a4b0d933d048a3b0f.tar.bz2 |
semantics.c (cxx_eval_constant_expression): Explain unacceptable use of variable better.
* semantics.c (cxx_eval_constant_expression): Explain
unacceptable use of variable better.
From-SVN: r166168
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 31 |
2 files changed, 35 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2e9f535..93f1b7a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2010-11-01 Jason Merrill <jason@redhat.com> + + * semantics.c (cxx_eval_constant_expression): Explain + unacceptable use of variable better. + 2010-11-01 Gabriel Dos Reis <gdr@cse.tamu.edu> Jason Merrill <jason@redhat.com> diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 397d383..2b8e9e3 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6513,7 +6513,36 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, if (DECL_P (r)) { if (!allow_non_constant) - error ("%qD cannot appear in a constant expression", r); + { + tree type = TREE_TYPE (r); + error ("the value of %qD is not usable in a constant " + "expression", r); + if (INTEGRAL_OR_ENUMERATION_TYPE_P (type)) + { + if (!CP_TYPE_CONST_P (type)) + inform (DECL_SOURCE_LOCATION (r), + "%q#D is not const", r); + else if (CP_TYPE_VOLATILE_P (type)) + inform (DECL_SOURCE_LOCATION (r), + "%q#D is volatile", r); + else if (!DECL_INITIAL (r)) + inform (DECL_SOURCE_LOCATION (r), + "%qD was not initialized with a constant " + "expression", r); + else + gcc_unreachable (); + } + else + { + if (cxx_dialect >= cxx0x && !DECL_DECLARED_CONSTEXPR_P (r)) + inform (DECL_SOURCE_LOCATION (r), + "%qD was not declared %<constexpr%>", r); + else + inform (DECL_SOURCE_LOCATION (r), + "%qD does not have integral or enumeration type", + r); + } + } *non_constant_p = true; } break; |