Hi,

fcntl.h as supplied on many glibc systems includes sys/stat.h in an extern "C" 
linkage block. Together with the use of namespaces in gnulib sys/stat.h this 
results in illegal (as in against the standard) C++ code.

Older gcc versions seem to have diagnosed this correctly, as there is a 
workaround for gcc < 4.3 already in place. Newer gcc versions allow this code, 
but intel icc does not. The bug is triggered when icc is used to compile 
Octave[1]. The bug can also be triggered using the gnulib-tool as follows:

# 1. set up the environment to use intel compilers
# 2. run the test suite:
# ./gnulib-tool --test --with-c++-tests fcntl sys_stat
###############
...snip...
/apps/intel/compiler/composer_xe_2013_sp1.2.144/bin/intel64/icpc -
DHAVE_CONFIG_H -I. -I../../gltests  -DGNULIB_STRICT_CHECKING=1 -I. -
I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib    
-MT test-fcntl-h-c++.o -MD -MP -MF .deps/test-fcntl-h-c++.Tpo -c -o test-
fcntl-h-c++.o ../../gltests/test-fcntl-h-c++.cc
In file included from /usr/include/fcntl.h(38),
                 from ../gllib/fcntl.h(61),
                 from ../../gltests/test-fcntl-h-c++.cc(22):
../gllib/sys/stat.h(657): error: declaration is incompatible with previous 
"fstat" (declared at line 214 of "/usr/include/sys/stat.h")
  _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
  ^

In file included from /usr/include/fcntl.h(38),
                 from ../gllib/fcntl.h(61),
                 from ../../gltests/test-fcntl-h-c++.cc(22):
../gllib/sys/stat.h(786): error: declaration is incompatible with previous 
"lstat" (declared at line 263 of "/usr/include/sys/stat.h")
  _GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
  ^

compilation aborted for ../../gltests/test-fcntl-h-c++.cc (code 2)
###################

The attached patch extends the previous workaround for gcc to apply to icc as 
well.

[1] https://savannah.gnu.org/bugs/index.php?43171

Cheers,
  Johannes

--- ./lib/fcntl.in.h.orig	2014-08-06 20:03:22.000000000 +0200
+++ ./lib/fcntl.in.h	2014-09-10 14:33:48.487911002 +0200
@@ -34,7 +34,7 @@
    extern "C" { ... } block, which leads to errors in C++ mode with the
    overridden <sys/stat.h> from gnulib.  These errors are known to be gone
    with g++ version >= 4.3.  */
-#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __INTEL_COMPILER || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))) 
 # include <sys/stat.h>
 #endif
 #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
@@ -53,7 +53,7 @@
    extern "C" { ... } block, which leads to errors in C++ mode with the
    overridden <sys/stat.h> from gnulib.  These errors are known to be gone
    with g++ version >= 4.3.  */
-#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __INTEL_COMPILER || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))) 
 # include <sys/stat.h>
 #endif
 /* The include_next requires a split double-inclusion guard.  */

Reply via email to