cwilkinson76 / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Compiling with -ansi -pedantic on Linux fails #334

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Compiling gtest and using it with -ansi -pedantic won't compile on Linux.

What steps will reproduce the problem?
1. CXXFLAGS="-ansi -pedantic" ./configure
2. make
3.

What is the expected output? What do you see instead?
It fails with:
g++ -DHAVE_CONFIG_H -I. -I./build-aux -I. -I./include -pthread 
-DGTEST_HAS_PTHREAD=1 -ansi -pedantic -MT src/gtest-all.lo -MD -MP -MF 
src/.deps/gtest-all.Tpo -c src/gtest-all.cc  -fPIC -DPIC -o 
src/.libs/gtest-all.o
In file included from ./include/gtest/gtest.h:64,
                 from src/gtest-all.cc:39:
./include/gtest/gtest-typed-test.h:239:46: warning: anonymous variadic macros 
were introduced in C99
In file included from ./include/gtest/internal/gtest-internal.h:40,
                 from ./include/gtest/gtest.h:57,
                 from src/gtest-all.cc:39:
./include/gtest/internal/gtest-port.h:1260: error: ISO C++ 1998 does not 
support ‘long long’
./include/gtest/internal/gtest-port.h:1448: error: ISO C++ 1998 does not 
support ‘long long’
./include/gtest/internal/gtest-port.h:1449: error: ISO C++ 1998 does not 
support ‘long long’
In file included from ./src/gtest.cc:128,
                 from src/gtest-all.cc:42:
./src/gtest-internal-inl.h: In function ‘bool 
testing::internal::ParseNaturalNumber(const std::string&, Integer*)’:
./src/gtest-internal-inl.h:1030: error: ISO C++ 1998 does not support ‘long 
long’
make: *** [src/gtest-all.lo] Error 1

What version of Google Test are you using? On what operating system?
gtest1.5 on Linux

$ g++ --version
g++ (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.

The attached simple patch fixes the problem.

Original issue reported on code.google.com by jens.k.mueller@gmail.com on 22 Nov 2010 at 1:22

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by w...@google.com on 14 Dec 2010 at 11:40

GoogleCodeExporter commented 9 years ago
int64_t is not in the standard, too. It appears to be GCC-ism, thus requiring a 
special case for GCC, lest other compilers choke on int64_t.

Also, I am not sure the type fix would be enough (please see this thread: 
https://groups.google.com/d/topic/googletestframework/p2YSDK99wbQ/discussion).

Original comment by vladlosev on 17 Dec 2010 at 7:43

GoogleCodeExporter commented 9 years ago
You're right. int64_t are not in defined in ISO C++ 1998.
But int64_t is part of ISO C99 but it's optional (see section 7.18 of 
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf (it's only a draft; I 
hope that it is correct)). I do not have access to the final release. I have no 
clue why gcc is compiling the code even though int64_t is not part of ISO C++ 
1998.
With the new C++ standard there will be some relief but I understand that it's 
not worth it for now.

Original comment by jens.k.mueller@gmail.com on 4 Jan 2011 at 12:57

GoogleCodeExporter commented 9 years ago
both int_least64_t and uint_least64_t are part of C99

imho, they would be good replacements for long long, considered that they 
enable G++ to compile the code with -pedantic.

they are typedefs defined in cstdint/stdint.h; which likely only MSVC++ doesn't 
support but there's preprocessing for this compiler.

See 7.18.1.1 Exact-width integer types, §3:

---

The following types are required:
  int_least8_t  uint_least8_t
  int_least16_t  uint_least_16_t
  int_least32_t  uint_least32_t
  int_least64_t  uint_least64_t
All other types of this form are optional.

---

see also Boost's cstdint: 
http://www.boost.org/doc/libs/1_45_0/libs/integer/doc/html/boost_integer/cstdint
.html

Original comment by gregory....@gmail.com on 8 Jan 2011 at 3:45