#211586 [PR 13071] no way to exclude backward C++ headers from include path

Package:
g++
Source:
gcc-defaults
Description:
GNU C++ compiler
Submitter:
Josh Stern
Date:
2022-03-17 17:36:05 UTC
Severity:
normal
Tags:
#211586#5
Date:
2003-09-18 20:01:36 UTC
From:
To:
Use of the C99 header <complex.h> in a C library header that
is then used within a C++ program causes compile/linkage
problems.   This problem was discovered via failing to compile
small examples using the m_get function in the meschach library
version included in Debian.   Here is a small example of some files to
show a minimal problem testcase:

****************** matfun.h **********************

#include <complex.h>

extern complex** getMat(int x, int y);

***************** matfun.c **********************
#include "matfun.h"

complex** getMat(int x, int y) {

  complex** ret;
  complex* v;
  int i;

  ret = (complex**) malloc(x*sizeof(complex*));
  for (i=0; i < x; i++) {
    ret[i] = (complex*) malloc(y*sizeof(complex));
  }
  return ret;
}
**************main.cc ***********************************************

extern "C" {
#include "matfun.h"
}

int main(int argc, char** argv) {

 complex** cp = getMat(5,5);
}

***************************************************************************


Error Msgs show compiler is confused by complex.h, mapping it
onto C++ complex type somehow:

g++ -I. -L. btest.cc -lmf
In file included from /usr/include/c++/3.3/backward/complex.h:31,
                 from matfun.h:2,
                 from btest.cc:3:
/usr/include/c++/3.3/backward/backward_warning.h:32:2: warning: #warning This
file includes at least one deprecated or antiquated header. Please consider
using one of the 32 headers found in section 17.4.1.2 of the C++ standard.
Examples include substituting the <X> header for the <X.h> header for C++
includes, or <sstream> instead of the deprecated header <strstream.h>. To
disable this warning use -Wno-deprecated.
In file included from /usr/include/c++/3.3/complex:49,
                 from /usr/include/c++/3.3/backward/complex.h:32,
                 from matfun.h:2,
                 from btest.cc:3:
/usr/include/c++/3.3/bits/cpp_type_traits.h:71: error: template with C linkage
/usr/include/c++/3.3/bits/cpp_type_traits.h:92: error: template with C linkage
/usr/include/c++/3.3/bits/cpp_type_traits.h:226: error: template with C
linkage
/usr/include/c++/3.3/bits/cpp_type_traits.h:266: error: template with C
linkage
/usr/include/c++/3.3/bits/cpp_type_traits.h:278: error: template with C
linkage
/usr/include/c++/3.3/bits/cpp_type_traits.h:290: error: template with C
linkage
In file included from /usr/include/c++/3.3/complex:50,
                 from /usr/include/c++/3.3/backward/complex.h:32,
                 from matfun.h:2,
                 from btest.cc:3:

etc. etc.

#211586#10
Date:
2003-09-18 20:57:35 UTC
From:
To:
Josh Stern wrote:

This is not a bug. The C99 complex type is not supported in
ISO C++98, or GNU C++.

Regards,
Martin

#211586#15
Date:
2003-09-18 22:30:45 UTC
From:
To:
I wasn't trying to actually do anything with C99's complex in
a C++ program.  At present,  g++ compilation fails with
misdirected error messages about templates if <complex.h>
is included at all, while the
compilation succeeds if the **same** file, /usr/include/complex.h
is copied to a file with a different name and then included under
that name.   If it is really felt necessary to continue to reserve
the name <complex.h> for C++ (even under C linkage directive)
then at least one might hope for a better error message.

-= Josh

#211586#26
Date:
2003-11-16 12:47:51 UTC
From:
To:
# submitted Debian report #211586 to gcc-gnats as PR 13071
# http://gcc.gnu.org/PR13071

forwarded 211586 http://gcc.gnu.org/PR13071
retitle 211586 [PR 13071] no way to exclude backward C++ headers from include path
tags 211586 + upstream
thanks