]> git.ipfire.org Git - thirdparty/gcc.git/commit
Implement C++20 P1301 [[nodiscard("should have a reason")]].
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 19 Oct 2019 04:51:59 +0000 (04:51 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 19 Oct 2019 04:51:59 +0000 (04:51 +0000)
commitf7df734fd9ccd9d8b5843f048ddb3fb1811c3030
tree9b2f5e5c5d3601b9c42221f4e30c262c62a681b4
parent0662fdaec6c38403cb3d0246412fcf6d501ec69d
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>
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277200 138bc75d-0d04-0410-961f-82ee72b054a4
17 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-lex.c
gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/parser.c
gcc/cp/tree.c
gcc/escaped_string.h [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/gen-attrs-67.C
gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
gcc/testsuite/g++.dg/cpp2a/nodiscard-constructor.c [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nodiscard-once.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nodiscard-reason-nonstring.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nodiscard-reason-only-one.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nodiscard-reason.C [new file with mode: 0644]
gcc/tree.c