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/escaped_string.h | |
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/escaped_string.h')
-rw-r--r-- | gcc/escaped_string.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/escaped_string.h b/gcc/escaped_string.h new file mode 100644 index 0000000..b83e128 --- /dev/null +++ b/gcc/escaped_string.h @@ -0,0 +1,43 @@ +/* Shared escaped string class. + Copyright (C) 1999-2019 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifndef GCC_ESCAPED_STRING_H +#define GCC_ESCAPED_STRING_H + +#include <cstdlib> + +/* 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 m_str; } + void escape (const char *); + private: + escaped_string(const escaped_string&) {} + escaped_string& operator=(const escaped_string&) { return *this; } + char *m_str; + bool m_owned; +}; + +#endif /* ! GCC_ESCAPED_STRING_H */ |