Googletest: Does googletest support C++0x/11?

Created on 28 Jul 2015  路  11Comments  路  Source: google/googletest

Does googletest support C++0x/11?
If not so, do you intend to support it later?

Using this library with -std=C++11 (-std=C++0x) for gcc is not possible due to 
a list of errors. I did not check it on VC++.

As far as using syntax sugar of new standards is very attractive, I think, it 
is good idea to support them.

Compliling several different binaries with different flags is not an option for 
it is not "easy to use". 

Thanks

Original issue reported on code.google.com by [email protected] on 23 Oct 2012 at 9:44

Priority-Medium Type-Defect auto-migrated

Most helpful comment

chartercap's comment uses -std=gnu++14. Actually the question was whether -std=c++11 is working.

I am working with Google Test 1.8.0 and gcc 6.4. This cannot be compiled using -std=c++11.

So the issue should not be closed.

All 11 comments

I too have struggled with this spending many hours trying to figure out why the 
errors manifest when trying to either compile or link gtest with my simple 
project which use the more current g++ 4.7.2 compiler and using the -std=c++11 
option either on my source files and/or gtest. 

I am attempting to use MinGW because I can easily find the current g++ compiler 
there but of course my research indicates that MinGW is poorly supported; 
double trouble for users like me I suppose but it would be nice to have help in 
getting this issue to work. 

Original comment by [email protected] on 31 Oct 2012 at 3:51

I am not sure if this is contributing to the problem. Just wanted to say that I 
am able to use gmock/gtest fine with current g++ 4.7.2 on MinGW, only I use 
-std=gnu+11 instead of -std=c++11. I've compiled gtest/gmock as well as my 
sources with -DGTEST_USE_OWN_TR1_TUPLE=0 and -DGTEST_HAS_PTHREAD=0.

I was able to use some of the c++11 extensions such as decltype, auto, rvalue 
references etc, just so if anyone wondering if I really am using c++11 syntax.

There are however issues one such is Issue 424 that prevents me from using DUMA 
for  memory leak detection. 

Original comment by [email protected] on 14 Dec 2012 at 10:24

successfully compiled gmock (gtest included) on osx 10.8.4 with cmake!
CMAKE_CXX_FLAGS = -DGTEST_USE_OWN_TR1_TUPLE=1 -DGTEST_HAS_TR1_TUPLE=1 
-std=c++11 -stdlib=libc++ -Wno-narrowing 
CMAKE_***_LINKER_FLAGS = -stdlib=libc++
The test targets failed to compile: gmock_build_tests, gtest_build_tests, but 
turning them off results successfull build. Currently I use this gmock lib, no 
problems so far.

Original comment by [email protected] on 11 Sep 2013 at 8:32

compiler: clang

Original comment by [email protected] on 11 Sep 2013 at 8:35

I tried to compile gtest with Cygwin using c++11 or c++03 but I had errors in 
both. gnu++11/gnu++03 seems to be working but not compatible with my project. 
Why we can't build it with standard flags?

Original comment by [email protected] on 11 Nov 2014 at 2:45

Is there any news on this? I failed find any knowledge regarding std flags.

Original comment by [email protected] on 3 Mar 2015 at 2:09

The fused source of 1.7.0 compiles happily with gcc 4.8.2 -std=gnu++0x

Original comment by [email protected] on 10 Apr 2015 at 9:26

Can be closed

gcc w/ c++14 on cygwin cmake
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DGTEST_OS_CYGWIN=1 -DGTEST_USE_OWN_TR1_TUPLE=1 -DGTEST_HAS_TR1_TUPLE=1 -std=gnu++14 -Wno-narrowing")

chartercap's comment uses -std=gnu++14. Actually the question was whether -std=c++11 is working.

I am working with Google Test 1.8.0 and gcc 6.4. This cannot be compiled using -std=c++11.

So the issue should not be closed.

It took some time, but I found a workaround. My concrete problem was that gcc did exclude some POSIX/XOPEN symbols when compiling with -std=c++11
This can be solved by defining the following symbols in the source code before any includes:

define _POSIX_SOURCE 1

define _XOPEN_SOURCE 500

This can also be done from the command line using the -D option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ElectricRCAircraftGuy picture ElectricRCAircraftGuy  路  4Comments

cyberdecker picture cyberdecker  路  3Comments

apivovarov picture apivovarov  路  3Comments

qiuxin picture qiuxin  路  5Comments

tschijnmo picture tschijnmo  路  4Comments