intl/plural.y: define macros to avoid multiple conflicting declarations of yyerror and yylex

Message ID 87zgp6mb03.fsf@autistici.org
State Committed
Delegated to: Arjun Shankar
Headers
Series intl/plural.y: define macros to avoid multiple conflicting declarations of yyerror and yylex |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Andrea Monaco Dec. 12, 2021, 9:24 a.m. UTC
  Hello.


My glibc 2.34 failed building on GNU/Hurd, though the problem may be
independent of the platform.

That's the error in intl/plural.y:

/root/glibc-2.34/build/intl/plural.c:69:25: error: static declaration of '__gettextlex' follows non-static declaration
   69 | #define yylex           __gettextlex
      |                         ^~~~~~~~~~~~
plural.y:57:12: note: in expansion of macro 'yylex'
   57 | static int yylex (YYSTYPE *lval, struct parse_args *arg);
      |            ^~~~~
/root/glibc-2.34/build/intl/plural.c:203:5: note: previous declaration of '__gettextlex' was here
  203 | int __gettextlex (YYSTYPE *yylvalp, struct parse_args *arg);
      |     ^~~~~~~~~~~~
/root/glibc-2.34/build/intl/plural.c:70:25: error: static declaration of '__gettexterror' follows non-static declaration
   70 | #define yyerror         __gettexterror
      |                         ^~~~~~~~~~~~~~
plural.y:58:13: note: in expansion of macro 'yyerror'
   58 | static void yyerror (struct parse_args *arg, const char *str);
      |             ^~~~~~~
/root/glibc-2.34/build/intl/plural.c:200:6: note: previous declaration of '__gettexterror' was here
  200 | void __gettexterror (struct parse_args *arg, const char *msg);
      |      ^~~~~~~~~~~~~~



The reason are these line in the generated build/intl/plural.c:

  #if !defined __gettexterror && !defined YYERROR_IS_DECLARED
  void __gettexterror (struct parse_args *arg, const char *msg);
  #endif
  #if !defined __gettextlex && !defined YYLEX_IS_DECLARED
  int __gettextlex (YYSTYPE *yylvalp, struct parse_args *arg);
  #endif

Those default prototypes provided by bison trigger a conflict between
multiple declarations.  This patch solves the issue.  Thanks.


Andrea Monaco
  

Comments

Arjun Shankar Dec. 21, 2021, 10:49 p.m. UTC | #1
Hi Andrea,

> My glibc 2.34 failed building on GNU/Hurd, though the problem may be
> independent of the platform.
>
> That's the error in intl/plural.y:
>
> /root/glibc-2.34/build/intl/plural.c:69:25: error: static declaration of '__gettextlex' follows non-static declaration
>    69 | #define yylex           __gettextlex
>       |                         ^~~~~~~~~~~~
> plural.y:57:12: note: in expansion of macro 'yylex'
>    57 | static int yylex (YYSTYPE *lval, struct parse_args *arg);
>       |            ^~~~~
> /root/glibc-2.34/build/intl/plural.c:203:5: note: previous declaration of '__gettextlex' was here
>   203 | int __gettextlex (YYSTYPE *yylvalp, struct parse_args *arg);
>       |     ^~~~~~~~~~~~
> /root/glibc-2.34/build/intl/plural.c:70:25: error: static declaration of '__gettexterror' follows non-static declaration
>    70 | #define yyerror         __gettexterror
>       |                         ^~~~~~~~~~~~~~
> plural.y:58:13: note: in expansion of macro 'yyerror'
>    58 | static void yyerror (struct parse_args *arg, const char *str);
>       |             ^~~~~~~
> /root/glibc-2.34/build/intl/plural.c:200:6: note: previous declaration of '__gettexterror' was here
>   200 | void __gettexterror (struct parse_args *arg, const char *msg);
>       |      ^~~~~~~~~~~~~~
>
>
>
> The reason are these line in the generated build/intl/plural.c:
>
>   #if !defined __gettexterror && !defined YYERROR_IS_DECLARED
>   void __gettexterror (struct parse_args *arg, const char *msg);
>   #endif
>   #if !defined __gettextlex && !defined YYLEX_IS_DECLARED
>   int __gettextlex (YYSTYPE *yylvalp, struct parse_args *arg);
>   #endif
>
> Those default prototypes provided by bison trigger a conflict between
> multiple declarations.  This patch solves the issue.  Thanks.

I'm trying to reproduce this and have been unable to see these lines
generated with bison-3.6.4, 3.7.6, and 3.8.2.

May I know which version of bison you're using? Or am I missing
something else here? I'm using Fedora but I expect that, like you
mentioned already and unless I'm mistaken, this shouldn't matter.

Thanks!
Arjun
  

Patch

diff --git a/intl/plural.y b/intl/plural.y
index e02e74541c..8573b56563 100644
--- a/intl/plural.y
+++ b/intl/plural.y
@@ -40,6 +40,11 @@ 
 # define __gettextparse PLURAL_PARSE
 #endif
 
+/* Later we provide those prototypes. Without these macros, bison may
+   generate its own prototypes with possible conflicts */
+#define YYLEX_IS_DECLARED
+#define YYERROR_IS_DECLARED
+
 %}
 %parse-param {struct parse_args *arg}
 %lex-param {struct parse_args *arg}