On 6/2/24 23:45, Andi Kleen wrote:
No intentional semantics change.
gcc/cp/ChangeLog:
* cp-tree.h (struct cstr): Add structure.
(get_cstr): Declare.
(extract_cstr): Declare.
(free_cstr): Declare.
* semantics.cc (finish_static_assert): Factor out constant
string expression extraction code and move to...
(get_cstr): Here.
(extract_cstr): Dito.
(free_cstr): Dito.
---
gcc/cp/cp-tree.h | 17 +++
gcc/cp/semantics.cc | 292 +++++++++++++++++++++++++-------------------
2 files changed, 184 insertions(+), 125 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 565e4a9290e2..25b8033db788 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -9015,6 +9015,23 @@ struct push_access_scope_guard
}
};
+/* Extracting strings from constexpr */
+
+/* Temporary data for extracting constant string. */
+struct cstr
+{
+ tree message;
+ tree message_data;
+ tree message_sz;
+ char *buf;
+};
+
+bool get_cstr (tree message, location_t location, const char *what, const char
*what2,
+ cstr &cstr);
+bool extract_cstr (const char *what, const char *what2, location_t location,
+ cstr &cstr, const char * & msg, int &len);
+void free_cstr (cstr &cstr);
get_ and extract_ are confusingly similar names. Let's make cstr more
of a class, initialized at least from 'message', and perhaps from the
other context information.
Then get_ can be something like cstr::type_check. And then free_cstr is
the destructor, and the copy constructor is deleted.
And please don't use the same name for the class and parameter/variables
of that type.
+ error_at (location, "%qs %s must be a string "
From ABOUT-GCC-NLS: "Avoid using %s to compose a diagnostic message
from multiple translatable strings; instead, write out the full
diagnostic message for each variant. Only use %s for message components
that do not need translation, such as keywords."
Also, if you are passing an English string for a diagnostic to a
function that isn't from diagnostic.h, you need to use the intl.h macros
to mark it for translation.
Jason