aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-10-02 11:21:14 -0400
committerJason Merrill <jason@redhat.com>2024-10-03 12:39:00 -0400
commitb6ff52a9957c05834351a39517dd49966cb1092c (patch)
treea6a1e8163fe637b9bce7419bc0a1b27d21236d2c /gcc/cp/parser.cc
parent5b08ae503dd4aef2789a667daaf1984e7cc94aaa (diff)
downloadgcc-b6ff52a9957c05834351a39517dd49966cb1092c.zip
gcc-b6ff52a9957c05834351a39517dd49966cb1092c.tar.gz
gcc-b6ff52a9957c05834351a39517dd49966cb1092c.tar.bz2
c++: add -Wdeprecated-literal-operator [CWG2521]
C++23 CWG issue 2521 (https://wg21.link/cwg2521) deprecates user-defined literal operators declared with the optional space between "" and the suffix. Many testcases used that syntax; I removed the space from most of them, and added C++23 warning tests to a few. CWG 2521 gcc/ChangeLog: * doc/invoke.texi: Document -Wdeprecated-literal-operator. gcc/c-family/ChangeLog: * c.opt: Add -Wdeprecated-literal-operator. * c-opts.cc (c_common_post_options): Default on in C++23. * c.opt.urls: Regenerate. gcc/cp/ChangeLog: * parser.cc (location_between): New. (cp_parser_operator): Handle -Wdeprecated-literal-operator. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/udlit-string-literal.h * g++.dg/cpp0x/Wliteral-suffix2.C * g++.dg/cpp0x/constexpr-55708.C * g++.dg/cpp0x/gnu_fext-numeric-literals.C * g++.dg/cpp0x/gnu_fno-ext-numeric-literals.C * g++.dg/cpp0x/pr51420.C * g++.dg/cpp0x/pr60209-neg.C * g++.dg/cpp0x/pr60209.C * g++.dg/cpp0x/pr61038.C * g++.dg/cpp0x/std_fext-numeric-literals.C * g++.dg/cpp0x/std_fno-ext-numeric-literals.C * g++.dg/cpp0x/udlit-addr.C * g++.dg/cpp0x/udlit-args-neg.C * g++.dg/cpp0x/udlit-args.C * g++.dg/cpp0x/udlit-args2.C * g++.dg/cpp0x/udlit-clink-neg.C * g++.dg/cpp0x/udlit-concat-neg.C * g++.dg/cpp0x/udlit-concat.C * g++.dg/cpp0x/udlit-constexpr.C * g++.dg/cpp0x/udlit-cpp98-neg.C * g++.dg/cpp0x/udlit-declare-neg.C * g++.dg/cpp0x/udlit-embed-quote.C * g++.dg/cpp0x/udlit-extended-id-1.C * g++.dg/cpp0x/udlit-extended-id-3.C * g++.dg/cpp0x/udlit-extern-c.C * g++.dg/cpp0x/udlit-friend.C * g++.dg/cpp0x/udlit-general.C * g++.dg/cpp0x/udlit-implicit-conv-neg-char8_t.C * g++.dg/cpp0x/udlit-implicit-conv-neg.C * g++.dg/cpp0x/udlit-inline.C * g++.dg/cpp0x/udlit-mangle.C * g++.dg/cpp0x/udlit-member-neg.C * g++.dg/cpp0x/udlit-namespace.C * g++.dg/cpp0x/udlit-nofunc-neg.C * g++.dg/cpp0x/udlit-nonempty-str-neg.C * g++.dg/cpp0x/udlit-nosuffix-neg.C * g++.dg/cpp0x/udlit-nounder-neg.C * g++.dg/cpp0x/udlit-operator-neg.C * g++.dg/cpp0x/udlit-overflow-neg.C * g++.dg/cpp0x/udlit-overflow.C * g++.dg/cpp0x/udlit-preproc-neg.C * g++.dg/cpp0x/udlit-raw-length.C * g++.dg/cpp0x/udlit-raw-op-string-neg.C * g++.dg/cpp0x/udlit-raw-op.C * g++.dg/cpp0x/udlit-raw-str.C * g++.dg/cpp0x/udlit-resolve-char8_t.C * g++.dg/cpp0x/udlit-resolve.C * g++.dg/cpp0x/udlit-shadow-neg.C * g++.dg/cpp0x/udlit-string-length.C * g++.dg/cpp0x/udlit-suffix-neg.C * g++.dg/cpp0x/udlit-template.C * g++.dg/cpp0x/udlit-tmpl-arg-neg.C * g++.dg/cpp0x/udlit-tmpl-arg-neg2.C * g++.dg/cpp0x/udlit-tmpl-arg.C * g++.dg/cpp0x/udlit-tmpl-parms-neg.C * g++.dg/cpp0x/udlit-tmpl-parms.C * g++.dg/cpp1y/pr57640.C * g++.dg/cpp1y/pr88872.C * g++.dg/cpp26/unevalstr1.C * g++.dg/cpp2a/concepts-pr60391.C * g++.dg/cpp2a/consteval-prop21.C * g++.dg/cpp2a/nontype-class6.C * g++.dg/cpp2a/udlit-class-nttp-ctad-neg.C * g++.dg/cpp2a/udlit-class-nttp-ctad-neg2.C * g++.dg/cpp2a/udlit-class-nttp-ctad.C * g++.dg/cpp2a/udlit-class-nttp-neg.C * g++.dg/cpp2a/udlit-class-nttp-neg2.C * g++.dg/cpp2a/udlit-class-nttp.C * g++.dg/ext/is_convertible2.C * g++.dg/lookup/pr87269.C * g++.dg/cpp0x/udlit_system_header: Adjust for C++23 deprecated operator "" _suffix. * g++.dg/DRs/dr2521.C: New test.
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r--gcc/cp/parser.cc33
1 files changed, 29 insertions, 4 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 0944827..08f9c89 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -943,6 +943,18 @@ make_location (cp_token *caret, cp_token *start, cp_token *end)
return make_location (caret->location, start->location, end->location);
}
+/* Location for the whitespace between two tokens. */
+
+static location_t
+location_between (cp_token *stok, cp_token *etok)
+{
+ location_t s = get_finish (stok->location);
+ s = linemap_position_for_loc_and_offset (line_table, s, 1);
+ location_t e = get_start (etok->location);
+ e = linemap_position_for_loc_and_offset (line_table, e, -1);
+ return make_location (s, s, e);
+}
+
/* nonzero if we are presently saving tokens. */
static inline int
@@ -18325,6 +18337,8 @@ cp_parser_operator (cp_parser* parser, location_t start_loc)
if (cxx_dialect == cxx98)
maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+ token = cp_lexer_peek_token (parser->lexer);
+
/* Consume the string. */
cp_expr str = cp_parser_userdef_string_literal (parser,
/*lookup_udlit=*/false);
@@ -18340,13 +18354,24 @@ cp_parser_operator (cp_parser* parser, location_t start_loc)
{
string_tree = str;
/* Look for the suffix identifier. */
- token = cp_lexer_peek_token (parser->lexer);
- if (token->type == CPP_NAME)
+ cp_token *id_tok = cp_lexer_peek_token (parser->lexer);
+ if (id_tok->type == CPP_NAME)
{
id = cp_parser_identifier (parser);
- end_loc = token->location;
+ end_loc = id_tok->location;
+
+ /* Deprecated by CWG2521 in C++23. */
+ if (warn_deprecated_literal_operator)
+ {
+ gcc_rich_location
+ space (location_between (token, id_tok));
+ space.add_fixit_remove ();
+ warning_at (&space, OPT_Wdeprecated_literal_operator,
+ "space between quotes and suffix is "
+ "deprecated in C++23");
+ }
}
- else if (token->type == CPP_KEYWORD)
+ else if (id_tok->type == CPP_KEYWORD)
{
error ("unexpected keyword;"
" remove space between quotes and suffix identifier");