GNU bug report logs - #68832
Testing: POSIX yacc and C++ linkage

Previous Next

Package: automake;

Reported by: Marcel Telka <marcel <at> telka.sk>

Date: Tue, 30 Jan 2024 23:59:02 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Marcel Telka <marcel <at> telka.sk>
To: 68832 <at> debbugs.gnu.org
Subject: bug#68832: Testing: POSIX yacc and C++ linkage
Date: Tue, 30 Jan 2024 21:35:41 +0100
[Message part 1 (text/plain, inline)]
Hi,

I ran tests for automake 1.16.5 on OpenIndiana and following 4 tests
failed:

FAIL: t/yacc-cxx.sh
FAIL: t/yacc-clean-cxx.sh
FAIL: t/yacc-d-cxx.sh
FAIL: t/yacc-mix-c-cxx.sh


The cause for the failure is this:

parse1.yy:30:7: error: conflicting declaration of 'void yyerror(const char*)' with 'C' linkage
parse1.yy:7:6: note: previous declaration with 'C++' linkage
    7 | void yyerror (const char *s) {}
      |      ^~~~~~~
parse1.yy:34:6: error: conflicting declaration of 'int yylex()' with 'C' linkage
parse1.yy:6:5: note: previous declaration with 'C++' linkage
    6 | int yylex (void) { return std::getchar (); }
      |     ^~~~~


For testing there is the default system yacc used.  It is the illumos
yacc as inherited from Solaris with some changes[1].  The generated code
that causes the failure is this:

 24 #if defined(__cplusplus) || defined(__STDC__)
 25 
 26 #if defined(__cplusplus)
 27 extern "C" {
 28 #endif
 29 #ifndef yyerror
 30 #if defined(__cplusplus)
 31         void yyerror(YYCONST char *);
 32 #endif
 33 #endif
 34 #ifndef yylex
 35         int yylex(void);
 36 #endif
 37         int yyparse(void);
 38 #if defined(__cplusplus)
 39 }
 40 #endif
 41 
 42 #endif

The issue is apparent.  The yacc generated code create both yyerror()
and yylex() with the C linkage, but testing expects C++ linkage.  This
is exactly what the compiler error says.

All of this is obvious.  So where is the bug and what should be fixed?
There are few possible views:

1. yacc is buggy and should not force C linkage for C++ source.  This is
grey area because POSIX says nothing about linkage or C++[2].

2. The tests' expectations about yacc behavior re C++ are too strong.
This seems to be true for illumos yacc.  Other yacc implementations, for
example GNU bison, does better job and do not force C linkage for
affected functions.

My proposal to solve the issue is to change affected tests to require
bison instead of yacc.  Please see attachment.


Thank you.


[1] for example this: https://www.illumos.org/issues/16136
[2] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/yacc.html

-- 
+-------------------------------------------+
| Marcel Telka   e-mail:   marcel <at> telka.sk  |
|                homepage: http://telka.sk/ |
+-------------------------------------------+
[automake-1.16.5-test-yacc-cxx-bison.patch (text/plain, attachment)]

This bug report was last modified 1 year and 127 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.