Loading ...
Sorry, an error occurred while loading the content.
 

weird C++ problem

Expand Messages
  • Apostolos Syropoulos
    Hello everybody, I was trying to compile a program and one file failed to compile with g++ 4.7.2 but it compiles with CC: Sun C++ 5.12 SunOS_i386 2011/11/16.
    Message 1 of 1 , Apr 1, 2013
      Hello everybody,

      I was trying to compile a program and one file failed to compile
      with g++ 4.7.2 but it compiles with CC: Sun C++ 5.12 SunOS_i386 2011/11/16.

      The following little program reproduces the error I got initially:

      #include <iostream>
      #include <string>
      using namespace std;
          namespace KPS {
              extern "C" {
                  #include <string.h> //it includes another header that eventually
              }                       // included this header.
          }
          using namespace KPS;

      int main() {
        std::string x;
        string y = "abcdef";
        cout << y << endl;
      }

      The error I am getting follows:

      yy.cpp: In function ‘int main()’:
      yy.cpp:12:3: error: reference to ‘std’ is ambiguous
      <built-in>:0:0: error: candidates are: namespace std { }
      In file included from /usr/include/string.h:33:0,
                       from yy.cpp:6:
      /usr/include/iso/string_iso.h:55:15: σφάλμα:                 namespace KPS::std { }
      yy.cpp:12:3: σφάλμα: reference to ‘std’ is ambiguous
      <built-in>:0:0: σφάλμα: candidates are: namespace std { }
      In file included from /usr/include/string.h:33:0,
                       from yy.cpp:6:
      /usr/include/iso/string_iso.h:55:15: σφάλμα:                 namespace KPS::std { }
      yy.cpp:12:15: σφάλμα: expected ‘;’ before ‘x’

      According to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773
      gcc 4.7.2 defines __cplusplus to be equal to 199711L. And of
      course CC assumes that the value of __cplusplus is
      199711L. The line in iso/string_iso.h that makes
      g++ to complain is line 55 of this file:

      line 54: #if __cplusplus >= 199711L
      line 55: namespace std {
      line 56: #endif

      Has anyone seen this thing before?

      A.S.

      ----------------------
      Apostolos Syropoulos
      Xanthi, Greece

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.