On mingw 10, I also see two compilation errors
../gllib/time.h:867:1: error: expected unqualified-id before string constant
867 | _GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
| ^~~~~~~~~~~~~~~~
../gllib/time.h: In member function 'gnulib::_gl_ctime_wrapper::operator
gnulib::_gl_ctime_wrapper::type() const':
../gllib/time.h:869:1: error: '::rpl_ctime' has not been declared; did you mean
'rpl_time'?
869 | _GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
| ^~~~~~~~~~~~~~~~
make[4]: *** [Makefile:24099: test-time-h-c++.o] Error 1
The problem is the _GL_ATTRIBUTE_DEPRECATED marker before _GL_FUNCDECL_RPL.
After macro expansion, the compiler sees
[[__deprecated__]] extern "C" char * rpl_ctime (...);
which is invalid syntax.
[[__deprecated__]] extern char * rpl_ctime (...);
would be valid syntax, but then we declare rpl_ctime with the wrong language
linkage.
Euh - did I say already that in C++, as a programmer, you waste time with
little things that in principle should not matter?
2023-04-19 Bruno Haible <[email protected]>
ctime: Fix compilation errors in C++ mode on mingw 10.
* lib/c++defs.h (_GL_FUNCDECL_RPL): Add a comment.
* lib/time.in.h (ctime): Don't use _GL_ATTRIBUTE_DEPRECATED before
_GL_FUNCDECL_RPL in C++ mode.
diff --git a/lib/c++defs.h b/lib/c++defs.h
index 8ad46951ad..458c014de5 100644
--- a/lib/c++defs.h
+++ b/lib/c++defs.h
@@ -99,6 +99,12 @@
Example:
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
_GL_ARG_NONNULL ((1)));
+
+ Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front
+ of a _GL_FUNCDECL_RPL invocation only in C mode, not in C++ mode. (That's
+ because
+ [[...]] extern "C" <declaration>;
+ is invalid syntax in C++.)
*/
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
diff --git a/lib/time.in.h b/lib/time.in.h
index 84cb1fa933..06428adb1d 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -356,7 +356,9 @@ _GL_CXXALIASWARN (strptime);
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define ctime rpl_ctime
# endif
+# ifndef __cplusplus
_GL_ATTRIBUTE_DEPRECATED
+# endif
_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));