The following code doesn't compile with g++:

  #include <vector>

  int time;

  int main() {}

Including the <vector> header brings the keyword "time" in global namespace. It
gives the following error:

  main.cpp:3: error: 'int time' redeclared as different kind of symbol
  /usr/include/time.h:187: error: previous declaration of 'time_t
time(time_t*)'

I'm not sure if that's a bug, but I don't think including <vector> should give
such results in C++. The time.h header, indirectly included via <vector> would
also be deprecated. The same code compiles fine with the comeau c++ online
test.

I'm not sure if gcc is responsible for the problem or if it's a problem with
the C library.

My gcc version info is:

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/usr --enable-shared
--enable-languages=c,c++,objc --enable-threads=posix --enable-__cxa_atexit
--disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu
--disable-libstdcxx-pch
Thread model: posix
gcc version 4.2.0


-- 
           Summary: #including <vector> brings keyword time in global
                    namespace.
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: olifant at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32371

Reply via email to