From 8ad0c477e888d34c8fc6dbcc008ef66505071d65 Mon Sep 17 00:00:00 2001 From: JeanHeyd Meneide Date: Sat, 19 Oct 2019 04:51:59 +0000 Subject: Implement C++20 P1301 [[nodiscard("should have a reason")]]. 2019-10-17 JeanHeyd Meneide 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 From-SVN: r277200 --- gcc/tree.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'gcc/tree.c') diff --git a/gcc/tree.c b/gcc/tree.c index e845fc7..2bee1d2 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -68,6 +68,7 @@ along with GCC; see the file COPYING3. If not see #include "regs.h" #include "tree-vector-builder.h" #include "gimple-fold.h" +#include "escaped_string.h" /* Tree code classes. */ @@ -13225,22 +13226,6 @@ typedef_variant_p (const_tree type) return is_typedef_decl (TYPE_NAME (type)); } -/* A class to handle converting a string that might contain - control characters, (eg newline, form-feed, etc), into one - in which contains escape sequences instead. */ - -class escaped_string -{ - public: - escaped_string () { m_owned = false; m_str = NULL; }; - ~escaped_string () { if (m_owned) free (m_str); } - operator const char *() const { return (const char *) m_str; } - void escape (const char *); - private: - char *m_str; - bool m_owned; -}; - /* PR 84195: Replace control characters in "unescaped" with their escaped equivalents. Allow newlines if -fmessage-length has been set to a non-zero value. This is done here, rather than -- cgit v1.1