Subject: Re: bug#34849: Compilation issues with g++ on some files

From: Alex <[email-masked]>
Date: Sat, 16 Mar 2019 23:22:11 -0600

Alex <[email-masked]> writes:

> I'm currently working on a prototype for a feature that requires the
> introduction of C++ files, and I am having some issues compiling certain
> files with g++. Any chance the below (particularly #3) could be easily
> fixed?
>
> 1. Invalid conversions to pvec_type. Compiling with the -fpermissive
> flag demotes these to warnings, but it would be nice to avoid using
> that.
>
> ./src/lisp.h: In function ‘pvec_type PSEUDOVECTOR_TYPE(const Lisp_Vector*)’:
> ./src/lisp.h:1683:11: error: invalid conversion from ‘long int’ to ‘pvec_type’ [-fpermissive]
>    return (size & PSEUDOVECTOR_FLAG
>           ~~~~~~~~~~~~~~~~~~~~~~~~~
>            ? (size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS
>            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>            : PVEC_NORMAL_VECTOR);
>            ~~~~~~~~~~~~~~~~~~~~~
> ./src/lisp.h: In function ‘bool PSEUDOVECTORP(Lisp_Object, int)’:
> ./src/lisp.h:1708:6: error: invalid conversion from ‘int’ to ‘pvec_type’ [-fpermissive]
>       code);
>       ^~~~
>
>
> 2. This one just needs a new (not new) variable name.
>
> ./src/lisp.h:1585:58: error: expected ‘,’ or ‘...’ before ‘new’
>  SSET (Lisp_Object string, ptrdiff_t index, unsigned char new)
>                                                           ^~~
> ./src/lisp.h: In function ‘void SSET(Lisp_Object, ptrdiff_t, unsigned char)’:
> ./src/lisp.h:1587:30: error: expected type-specifier before ‘;’ token
>    SDATA (string)[index] = new;
>                               ^
>
>
> 3. I'm not sure what to do for the next one, which is unfortunately
> included by other files.
>
> ./lib/time.h:769:1: error: expected ‘,’ or ‘...’ before ‘__timer’
>  _GL_FUNCDECL_SYS (localtime_rz, struct tm *,
>  ^~~~~~~~~~~~~~~~
> ./lib/time.h:771:50: error: nonnull argument with out-of-range operand number (argument 2, operand 3)
>                     struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
>                                                   ^~~~~~~~~~~~~~~
> ./lib/time.h:775:1: error: expected ‘,’ or ‘...’ before ‘__result’
>  _GL_FUNCDECL_SYS (mktime_z, time_t,
>  ^~~~~~~~~~~~~~~~

I managed to work around #3 by editing lib/time.h.in directly, but now
I've hit another issue: compiling lisp.h inside of an extern "C" block.
This gets me the following error:

--8<---------------cut here---------------start------------->8---
./lib/verify.h:178:1: error: template with C linkage
 template <int w>
--8<---------------cut here---------------end--------------->8---

Paul, do you have any ideas on how to fix this?  Is there a solution
that works both when __cplusplus is defined and when using C linkage?