gmock_doctor has problems figuring out that ReturnRef should be used

374 views
Skip to first unread message

jo.t

unread,
Sep 6, 2011, 4:44:28 PM9/6/11
to Google C++ Mocking Framework
hello,

the used declaration of mock method is:

MOCK_CONST_METHOD1(get, const std::complex<double>& (const size_t
index));

here is the respective expect-declaration:

std::complex<double> dummy(0., 0.);
EXPECT_CALL(_block, get(_))
.WillOnce(Return(dummy));

-> gcc complained:

/usr/include/gmock/gmock-actions.h:449: error: creating array with
negative size (‘-0x00000000000000001’)

after looking at gmock_doctor's source, i was able to figure out, that
it should use ReturnRef. so i guess the regex is a little too
restrictive.

regards

Vlad Losev

unread,
Sep 16, 2011, 8:02:12 AM9/16/11
to Google C++ Mocking Framework
Can you post you gcc version and the complete diagnostic it produces? Also, the doctor has been recently updated in SVN. You may want to try the latest version.

jo.t

unread,
Sep 18, 2011, 3:35:49 PM9/18/11
to Google C++ Mocking Framework
I just checked with the latest trunk version of gmock_doctor - also
not working.

gcc --version: gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2

I'm not sure what you mean by "diagnostic". If you're talking about
the compiler's diagnostic regarding my mocking code, see below.

Thanks for you help!


In file included from /usr/include/gmock/gmock.h:
58:0,
from foo.cpp:4:
/usr/include/gmock/gmock-actions.h: In member function
‘testing::internal::ReturnAction<R>::operator testing::Action<Func>()
const [with F = const std::complex<double>&(unsigned int), R =
std::complex<double>]’:
foo.cpp:116:28: instantiated from here
/usr/include/gmock/gmock-actions.h:449:5: error: creating array with
negative size (‘-0x00000000000000001’)




Vlad Losev

unread,
Sep 22, 2011, 7:21:05 PM9/22/11
to Google C++ Mocking Framework
I've noticed that you compiler output uses left and right single quotation marks (U+2018 and U+2019) instead of apostropes (U+0027) when quoting identifiers. Assuming this is not an artifact of copying/pasting and is really what your compiler produces, try this patch and see whether it fixes the problem for you (mind, it is against the SVN head, not a release):

Index: scripts/gmock_doctor.py
===================================================================
--- scripts/gmock_doctor.py (revision 395)
+++ scripts/gmock_doctor.py (working copy)
@@ -559,6 +559,7 @@
   """Generates all possible diagnoses given the compiler error message."""
 
   msg = re.sub(r'\x1b\[[^m]*m', '', msg)  # Strips all color formatting.
+  msg = re.sub(r'[‘’]', "'", msg)  # Replaces left and right quotes with apostrophes.
 
   diagnoses = []
   for diagnoser in _DIAGNOSERS:
<end of patch>

HTH,
Vlad

jo.t

unread,
Sep 23, 2011, 1:40:38 PM9/23/11
to Google C++ Mocking Framework
Hi Vlad,

thanks so far!

Strange things... I'm using standard GCC as distributed with
(K)Ubuntu.

Unfortunately, your patch doesn't help. The error remains.
After applying your patch, I had to add

# -*- coding: utf-8 -*-

...to the beginning of gmock_doctor.py. Otherwise, Python would reject
the file with:

File "gmock_doctor.py", line 563
SyntaxError: Non-ASCII character '\xe2' in file gmock_doctor.py on
line 563, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details

I verified the characters your patch is trying to replace. They are
the same as GCC prints on the console. So that should be fine... Any
further ideas?

Thanks anyway,
Jonas

Vlad Losev

unread,
Sep 23, 2011, 3:19:49 PM9/23/11
to Google C++ Mocking Framework
Jonas,

Can you post the complete output from the compiler in a text file attachment, to better preserve it?

jo.t

unread,
Sep 25, 2011, 2:42:02 PM9/25/11
to Google C++ Mocking Framework
Vlad,

unfortunately the groups webinterface won't let me attach a file.
Anyway, here we go: http://www.fileserve.com/file/ByVgJbA/gcc_error.txt

Vlad Losev

unread,
Sep 26, 2011, 2:38:12 PM9/26/11
to Google C++ Mocking Framework
Jonas - try this patch, then:

Index: scripts/gmock_doctor.py
===================================================================
--- scripts/gmock_doctor.py (revision 395)
+++ scripts/gmock_doctor.py (working copy)
@@ -128,7 +128,7 @@
     ]
 
 # Regex for matching source file path and line number in the compiler's errors.
-_GCC_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):\s+'
+_GCC_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):(?P<column>\d+)?:\s+'
 _CLANG_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):(?P<column>\d+):\s+'
 _CLANG_NON_GMOCK_FILE_LINE_RE = (
     r'(?P<file>.*[/\\^](?!gmock-)[^/\\]+):(?P<line>\d+):(?P<column>\d+):\s+')
@@ -559,6 +559,9 @@
   """Generates all possible diagnoses given the compiler error message."""
 
   msg = re.sub(r'\x1b\[[^m]*m', '', msg)  # Strips all color formatting.
+  # Assuming the string is using the UTF-8 encoding, replaces the left and
+  # the right single quote characters with apostrophes.
+  msg = re.sub(r'(\xe2\x80\x98|\xe2\x80\x99)', "'", msg)
 
   diagnoses = []
   for diagnoser in _DIAGNOSERS:


jo.t

unread,
Sep 26, 2011, 5:20:55 PM9/26/11
to Google C++ Mocking Framework
Yep, that one works, Vlad. The doctor diagnoses the "Return instead of
ReturnRef"-disease correctly now. :-)
Thanks a lot for your help on this!

Vlad Losev

unread,
Sep 28, 2011, 2:36:09 PM9/28/11
to jo.t, Google C++ Mocking Framework
This is now committed into SVN, revision 399.

On Mon, Sep 26, 2011 at 2:20 PM, jo.t <jonas.t...@gmail.com> wrote:
Yep, that one works, Vlad. The doctor diagnoses the "Return instead of
ReturnRef"-disease correctly now. :-)
Thanks a lot for your help on this!

You are welcome :) 
Reply all
Reply to author
Forward
0 new messages