diff options
author | Ed Smith-Rowland <3dw4rd@verizon.net> | 2012-11-29 02:30:44 +0000 |
---|---|---|
committer | Edward Smith-Rowland <emsr@gcc.gnu.org> | 2012-11-29 02:30:44 +0000 |
commit | 2d7aa5780cebd11f16917ca3983cfd65b457317a (patch) | |
tree | 82d134dee495ddba8519c473b5cbfa7009581d18 /gcc/cp | |
parent | 48ac1c945b6960be0f88ed15d6f17ae4788d58db (diff) | |
download | gcc-2d7aa5780cebd11f16917ca3983cfd65b457317a.zip gcc-2d7aa5780cebd11f16917ca3983cfd65b457317a.tar.gz gcc-2d7aa5780cebd11f16917ca3983cfd65b457317a.tar.bz2 |
re PR c++/52654 ([C++11] Warn on overflow in user-defined literals)
gcc/c-family/
2012-11-29 Ed Smith-Rowland <3dw4rd@verizon.net>
PR c++/52654
* c-common.h (overflow_type): New enum.
(build_userdef_literal): Add overflow_type argument.
(tree_userdef_literal): Add overflow_type.
(USERDEF_LITERAL_OVERFLOW): New access macro.
* c-common.c (build_userdef_literal): Add overflow_type
argument.
* c-lex.c (c_lex_with_flags): Add overflow_type to
build_userdef_literal calls.
(interpret_integer, interpret_float): Add overflow_type argument.
gcc/cp/
2012-11-29 Ed Smith-Rowland <3dw4rd@verizon.net>
PR c++/52654
* parser.c (cp_parser_string_literal): Add overflow_type arg.
(cp_parser_userdef_numeric_literal): Warn on numeric overflow.
gcc/testsuite/
2012-11-29 Ed Smith-Rowland <3dw4rd@verizon.net>
PR c++/52654
* g++.dg/cpp0x/udlit-overflow.C: New.
* g++.dg/cpp0x/udlit-overflow-neg.C: New.
From-SVN: r193918
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8c30eaa..c202bdf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-11-29 Ed Smith-Rowland <3dw4rd@verizon.net> + + PR c++/52654 + * parser.c (cp_parser_string_literal): Add overflow_type arg. + (cp_parser_userdef_numeric_literal): Warn on numeric overflow. + 2012-11-28 Andrew Pinski <apinski@cavium.com> PR bootstrap/54279 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a2d8062..1fe6246 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3529,7 +3529,8 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok) if (have_suffix_p) { - tree literal = build_userdef_literal (suffix_id, value, NULL_TREE); + tree literal = build_userdef_literal (suffix_id, value, + OT_NONE, NULL_TREE); tok->u.value = literal; return cp_parser_userdef_string_literal (tok); } @@ -3661,6 +3662,7 @@ cp_parser_userdef_numeric_literal (cp_parser *parser) tree literal = token->u.value; tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal); tree value = USERDEF_LITERAL_VALUE (literal); + int overflow = USERDEF_LITERAL_OVERFLOW (literal); tree num_string = USERDEF_LITERAL_NUM_STRING (literal); tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id)); tree decl, result; @@ -3676,6 +3678,20 @@ cp_parser_userdef_numeric_literal (cp_parser *parser) result = finish_call_expr (decl, &args, false, true, tf_none); if (result != error_mark_node) { + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE && overflow > 0) + warning_at (token->location, OPT_Woverflow, + "integer literal exceeds range of %qT type", + long_long_unsigned_type_node); + else + { + if (overflow > 0) + warning_at (token->location, OPT_Woverflow, + "floating literal exceeds range of %qT type", + long_double_type_node); + else if (overflow < 0) + warning_at (token->location, OPT_Woverflow, + "floating literal truncated to zero"); + } release_tree_vector (args); return result; } |