aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2022-11-11 17:59:30 -0500
committerMarek Polacek <polacek@redhat.com>2023-01-26 10:06:20 -0500
commit9f353b0c1dc9385ba8b8a64b65d66d5452383c11 (patch)
tree46eb0c0e167e6da608f961bd74cf4212d62f112f /gcc/c-family
parentf1eab269288ffa80ba924ddb4c4b36f8f781d613 (diff)
downloadgcc-9f353b0c1dc9385ba8b8a64b65d66d5452383c11.zip
gcc-9f353b0c1dc9385ba8b8a64b65d66d5452383c11.tar.gz
gcc-9f353b0c1dc9385ba8b8a64b65d66d5452383c11.tar.bz2
c++: Reject UDLs in certain contexts [PR105300]
In this PR, we are crashing because we've encountered a UDL where a string-literal is expected. This patch makes the parser reject string and character UDLs in all places where the grammar requires a string-literal and not a user-defined-string-literal. I've introduced two new wrappers; the existing cp_parser_string_literal was renamed to cp_parser_string_literal_common and should not be called directly. finish_userdef_string_literal is renamed from cp_parser_userdef_string_literal. PR c++/105300 gcc/c-family/ChangeLog: * c-pragma.cc (handle_pragma_message): Warn for CPP_STRING_USERDEF. gcc/cp/ChangeLog: * parser.cc: Remove unnecessary forward declarations. (cp_parser_string_literal): New wrapper. (cp_parser_string_literal_common): Renamed from cp_parser_string_literal. Add a bool parameter. Give an error when UDLs are not permitted. (cp_parser_userdef_string_literal): New wrapper. (finish_userdef_string_literal): Renamed from cp_parser_userdef_string_literal. (cp_parser_primary_expression): Call cp_parser_userdef_string_literal instead of cp_parser_string_literal. (cp_parser_linkage_specification): Move a variable declaration closer to its first use. (cp_parser_static_assert): Likewise. (cp_parser_operator): Call cp_parser_userdef_string_literal instead of cp_parser_string_literal. (cp_parser_asm_definition): Move a variable declaration closer to its first use. (cp_parser_asm_specification_opt): Move variable declarations closer to their first use. (cp_parser_asm_operand_list): Likewise. (cp_parser_asm_clobber_list): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/udlit-error1.C: New test.
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/c-pragma.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 68d1c8b..0d2b333 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1390,6 +1390,9 @@ handle_pragma_message (cpp_reader *)
}
else if (token == CPP_STRING)
message = x;
+ else if (token == CPP_STRING_USERDEF)
+ GCC_BAD ("string literal with user-defined suffix is invalid in this "
+ "context");
else
GCC_BAD ("expected a string after %<#pragma message%>");