1.7.0 does not compile with -std=c++0x flag on gcc 4.6

1,997 views
Skip to first unread message

Martyn Gigg

unread,
Nov 13, 2013, 4:37:10 AM11/13/13
to googl...@googlegroups.com
Our project embeds googlemock into a larger CMake project and we use the -std=c++0x flag on gcc.

This worked with gmock-1.6 but fails with the following output on gmock-1.7

Scanning dependencies of target gmock
[ 14%] Building CXX object CMakeFiles/gmock.dir/gtest/src/gtest-all.cc.o
[ 28%] Building CXX object CMakeFiles/gmock.dir/src/gmock-all.cc.o
In file included from /mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-spec-builders.h:75:0,
                 from /mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-generated-function-mockers.h:43,
                 from /mnt/data1/Code/gmock-1.7.0/include/gmock/gmock.h:61,
                 from /mnt/data1/Code/gmock-1.7.0/src/gmock-all.cc:40:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1485:41: sorry, unimplemented: cannot expand ‘Tail ...’ into a fixed-length argument list
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1486:63: error: template argument 2 is invalid
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h: In static member function ‘static testing::internal::MatcherList<kSize, Head, Tail>::ListType testing::internal::MatcherList<kSize, Head, Tail>::BuildList(const Head&, const Tail& ...)’:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1493:20: error: expected primary-expression before ‘(’ token
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1493:30: error: ‘MatcherListTail’ is not a class, namespace, or enumeration
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h: In static member function ‘static testing::Matcher<T> testing::internal::MatcherList<kSize, Head, Tail>::CreateMatcher(const ListType&)’:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1503:37: error: request for member ‘first’ in ‘matchers’, which is of non-class type ‘const ListType {aka const int}’
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1505:22: error: request for member ‘second’ in ‘matchers’, which is of non-class type ‘const ListType {aka const int}’
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1502:22: error: expected primary-expression before ‘(’ token
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1503:37: error: request for member ‘first’ in ‘matchers’, which is of non-class type ‘const ListType {aka const int}’
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1504:9: error: ‘MatcherListTail’ is not a class, namespace, or enumeration
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1504:50: error: expected primary-expression before ‘,’ token
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1504:68: error: missing template arguments before ‘>’ token
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1505:22: error: request for member ‘second’ in ‘matchers’, which is of non-class type ‘const ListType {aka const int}’
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h: At global scope:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1548:47: sorry, unimplemented: cannot expand ‘Args ...’ into a fixed-length argument list
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1550:18: error: ‘MatcherListType’ is not a class, namespace, or enumeration
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h: In constructor ‘testing::internal::VariadicMatcher<CombiningMatcher, Args>::VariadicMatcher(const Args& ...)’:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1536:19: error: ‘MatcherListType’ is not a class, namespace, or enumeration
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h: In member function ‘testing::internal::VariadicMatcher<CombiningMatcher, Args>::operator testing::Matcher<T>() const’:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1543:12: error: ‘MatcherListType’ is not a class, namespace, or enumeration
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1543:53: error: expected primary-expression before ‘,’ token
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1543:71: error: missing template arguments before ‘>’ token
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h: At global scope:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1556:1: error: expected unqualified-id before ‘using’
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:1650:1: error: expected unqualified-id before ‘using’
In file included from /mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-spec-builders.h:75:0,
                 from /mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-generated-function-mockers.h:43,
                 from /mnt/data1/Code/gmock-1.7.0/include/gmock/gmock.h:61,
                 from /mnt/data1/Code/gmock-1.7.0/src/gmock-all.cc:40:
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:3954:8: error: ‘AllOfMatcher’ in namespace ‘testing::internal’ does not name a type
/mnt/data1/Code/gmock-1.7.0/include/gmock/gmock-matchers.h:3959:8: error: ‘AnyOfMatcher’ in namespace ‘testing::internal’ does not name a type
make[2]: *** [CMakeFiles/gmock.dir/src/gmock-all.cc.o] Error 1
make[1]: *** [CMakeFiles/gmock.dir/all] Error 2
make: *** [all] Error 2


What steps will reproduce the problem?
1. cd gmock-1.7.0
2. mkdir build && cd build
2. CXXFLAGS="-std=c++0x" cmake ../
3. make

What is the expected output? What do you see instead?
The expected output is that the code compiles and gmock/gtest libraries are produced.

Which version of Google Mock are you using? On what operating system?
Using googlemock version 1.7.0 on Ubuntu 12.04 with gcc version: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Vlad Losev

unread,
Nov 13, 2013, 10:15:12 AM11/13/13
to Google C++ Mocking Framework

1.7 implemented AllOf and AnyOf using variadic templates in C++11 mode in order to remove limitations on the number of their arguments. It seems to be hitting a bug in GCC which was fixed in 4.7.

For now, I guess you can either upgrade your GCC to 4.7, revert back to using gmock 1.7, or stop using -std=c++0x.


--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/4342d390-77b8-4c9f-8a3a-dce789922db8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Martyn Gigg

unread,
Nov 17, 2013, 12:53:19 PM11/17/13
to googl...@googlegroups.com
I see. Many thanks for the information.

We will stick to using 1.6 for now.

Lukasz Forynski

unread,
Jan 5, 2015, 10:30:45 AM1/5/15
to googl...@googlegroups.com
Or perhaps gmock could be patched to skip this variadic implementation for matchers for gcc < 4.7,
i.e. something like:

===================================================================
--- include/gmock/gmock-matchers.h    (revision 501)
+++ include/gmock/gmock-matchers.h    (working copy)
@@ -1591,7 +1591,10 @@
         
SafeMatcherCast<T>(matchers.second)));
   
}
 
};
-
+// Skip variadic implementation of matchers if using GCC < 4.7 due to
+// Bug 35722 -[C++0x] Variadic templates expansion into non-variadic class template
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35722
+#if !defined(__GNUC__) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7 ) )
 
// VariadicMatcher is used for the variadic implementation of
 
// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
 
// CombiningMatcher<T> is used to recursively combine the provided matchers
@@ -1621,7 +1624,7 @@
 
 
template <typename... Args>
 
using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
-
+#endif  // GCC >= 4.7
 
#endif  // GTEST_LANG_CXX11
 
 
// Used for implementing the AllOf(m_1, ..., m_n) matcher, which




On Wednesday, November 13, 2013 3:15:12 PM UTC, Vlad Losev wrote:
Reply all
Reply to author
Forward
0 new messages