diff options
author | JeanHeyd Meneide <phdofthehouse@gmail.com> | 2019-10-19 04:51:59 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2019-10-19 00:51:59 -0400 |
commit | 8ad0c477e888d34c8fc6dbcc008ef66505071d65 (patch) | |
tree | 9b2f5e5c5d3601b9c42221f4e30c262c62a681b4 /gcc/cp/tree.c | |
parent | 9299523c9aad158f5276df2bfe777044bb144230 (diff) | |
download | gcc-8ad0c477e888d34c8fc6dbcc008ef66505071d65.zip gcc-8ad0c477e888d34c8fc6dbcc008ef66505071d65.tar.gz gcc-8ad0c477e888d34c8fc6dbcc008ef66505071d65.tar.bz2 |
Implement C++20 P1301 [[nodiscard("should have a reason")]].
2019-10-17 JeanHeyd Meneide <phdofthehouse@gmail.com>
gcc/
* escaped_string.h (escaped_string): New header.
* tree.c (escaped_string): Remove escaped_string class.
gcc/c-family
* c-lex.c (c_common_has_attribute): Update nodiscard value.
gcc/cp/
* tree.c (handle_nodiscard_attribute) Added C++2a nodiscard
string message.
(std_attribute_table) Increase nodiscard argument handling
max_length from 0 to 1.
* parser.c (cp_parser_check_std_attribute): Add requirement
that nodiscard only be seen once in attribute-list.
(cp_parser_std_attribute): Check that empty parenthesis lists are
not specified for attributes that have max_length > 0 (e.g.
[[attr()]]).
* cvt.c (maybe_warn_nodiscard): Add nodiscard message to
output, if applicable.
(convert_to_void): Allow constructors to be nodiscard-able (P1771).
gcc/testsuite/g++.dg/cpp0x
* gen-attrs-67.C: Test new error message for empty-parenthesis-list.
gcc/testsuite/g++.dg/cpp2a
* nodiscard-construct.C: New test.
* nodiscard-once.C: New test.
* nodiscard-reason-nonstring.C: New test.
* nodiscard-reason-only-one.C: New test.
* nodiscard-reason.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
From-SVN: r277200
Diffstat (limited to 'gcc/cp/tree.c')
-rw-r--r-- | gcc/cp/tree.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7f71891..a004bb1 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -4369,9 +4369,14 @@ zero_init_p (const_tree t) warn_unused_result attribute. */ static tree -handle_nodiscard_attribute (tree *node, tree name, tree /*args*/, +handle_nodiscard_attribute (tree *node, tree name, tree args, int /*flags*/, bool *no_add_attrs) { + if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST) + { + error ("%qE attribute argument must be a string constant", name); + *no_add_attrs = true; + } if (TREE_CODE (*node) == FUNCTION_DECL) { if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))) @@ -4461,7 +4466,7 @@ const struct attribute_spec std_attribute_table[] = affects_type_identity, handler, exclude } */ { "maybe_unused", 0, 0, false, false, false, false, handle_unused_attribute, NULL }, - { "nodiscard", 0, 0, false, false, false, false, + { "nodiscard", 0, 1, false, false, false, false, handle_nodiscard_attribute, NULL }, { "no_unique_address", 0, 0, true, false, false, false, handle_no_unique_addr_attribute, NULL }, |