[COMMITTED] a68: a68_phrase_to_text and a68_mode_error_text return const char pointers

Jose E. Marchesi jemarch@gnu.org
Fri Oct 24 08:51:14 GMT 2025


The functions a68_phrase_to_text and a68_mode_error_text operate on
static buffers and return pointers to them.  These pointer shall be
const.

gcc/ChangeLog

	* algol68/a68-moids-diagnostics.cc (a68_mode_error_text): Return
	const pointer.
	(a68_cannot_coerce): Expect const char pointer from
	a68_mode_error_text.
	* algol68/a68-parser-top-down.cc (a68_phrase_to_text): Likewise.
	* algol68/a68-parser-bottom-up.cc (recover_from_error): Expect
	const char pointer from a68_phrase_to_text.
	* algol68/a68.h: Adapt prototypes accordingly.
---
 gcc/algol68/a68-moids-diagnostics.cc | 4 ++--
 gcc/algol68/a68-parser-bottom-up.cc  | 2 +-
 gcc/algol68/a68-parser-top-down.cc   | 2 +-
 gcc/algol68/a68.h                    | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/algol68/a68-moids-diagnostics.cc b/gcc/algol68/a68-moids-diagnostics.cc
index 1bc461d22ef..bd9638cb36c 100644
--- a/gcc/algol68/a68-moids-diagnostics.cc
+++ b/gcc/algol68/a68-moids-diagnostics.cc
@@ -28,7 +28,7 @@
 
 /* Give accurate error message.  */
 
-char *
+const char *
 a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, int depth)
 {
 #define TAIL(z) (&(z)[strlen (z)])
@@ -216,7 +216,7 @@ a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, i
 void
 a68_cannot_coerce (NODE_T *p, MOID_T *from, MOID_T *to, int context, int deflex, int att)
 {
-  char *txt = a68_mode_error_text (p, from, to, context, deflex, 1);
+  const char *txt = a68_mode_error_text (p, from, to, context, deflex, 1);
 
   if (att == STOP)
     {
diff --git a/gcc/algol68/a68-parser-bottom-up.cc b/gcc/algol68/a68-parser-bottom-up.cc
index 9a914dd2c52..2f7f165f4d0 100644
--- a/gcc/algol68/a68-parser-bottom-up.cc
+++ b/gcc/algol68/a68-parser-bottom-up.cc
@@ -2328,7 +2328,7 @@ recover_from_error (NODE_T * p, enum a68_attribute expect, bool suppress)
     {
       /* Give an error message.  */
       NODE_T *w = p;
-      char *seq = a68_phrase_to_text (p, &w);
+      const char *seq = a68_phrase_to_text (p, &w);
       if (strlen (seq) == 0)
 	{
 	  if (ERROR_COUNT (&A68_JOB) == 0)
diff --git a/gcc/algol68/a68-parser-top-down.cc b/gcc/algol68/a68-parser-top-down.cc
index 7a39b3fcad5..cfb4ae7ceca 100644
--- a/gcc/algol68/a68-parser-top-down.cc
+++ b/gcc/algol68/a68-parser-top-down.cc
@@ -58,7 +58,7 @@ a68_substitute_brackets (NODE_T *p)
 
 /* Intelligible diagnostic from syntax tree branch.  */
 
-char *
+const char *
 a68_phrase_to_text (NODE_T * p, NODE_T ** w)
 {
 #define MAX_TERMINALS 8
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index 08686059a2a..11c99b541a8 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -282,7 +282,7 @@ location_t a68_get_line_location (LINE_T *line, const char *pos);
 /* a68-parser-top-down.cc  */
 
 void a68_substitute_brackets (NODE_T *p);
-char *a68_phrase_to_text (NODE_T *p, NODE_T **w);
+const char *a68_phrase_to_text (NODE_T *p, NODE_T **w);
 void a68_top_down_parser (NODE_T *p);
 
 /* a68-parser-bottom-up.cc  */
@@ -450,7 +450,7 @@ void a68_serial_dsa (NODE_T *p);
 
 /* a68-moids-diagnostics.cc  */
 
-char *a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, int depth);
+const char *a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, int depth);
 void a68_cannot_coerce (NODE_T *p, MOID_T *from, MOID_T *to, int context, int deflex, int att);
 void a68_warn_for_voiding (NODE_T *p, SOID_T *x, SOID_T *y, int c);
 void a68_semantic_pitfall (NODE_T *p, MOID_T *m, int c, int u);
-- 
2.30.2



More information about the Algol68 mailing list