Search code examples
c++gccgoogletestgooglemock

GMock macros not recognized? YCM gives me error, but Bazel builds fine


I am using YCM to provide error checking for my Vim setup. It is throwing errors saying "C++ requires a type specifier for all declarations" at my use of MOCK_METHOD, but Bazel is building just fine. I think I am missing some sort of flag?

This guy has the same problem but did not return to give an answer:

https://github.com/ycm-core/YouCompleteMe/issues/1332

Judging by the person's reply, I knew it was something with my YCM config so I checked that but to no avail.

Here is the simple code

#include <netinet/in.h>
#include <gmock/gmock.h>
#include <string>
#include "socket_helper.h"

namespace Proj {

class MockSocketHelper : public SocketHelper {
 public:
  MOCK_METHOD(ssize_t, write, (std::string msg), (override));
  MOCK_METHOD(std::string, read, (size_t n_bytes), (override));
};

at MOCK_METHOD I get "C++ requires a type specifier for all declarations" which to me tells me it doesn't recognize the macro.

Here are the base flags in my ycmd config:

BASE_FLAGS = [
        '-Wall',
        '-Wextra',
        '-Werror',
        '-Wno-long-long',
        '-Wno-variadic-macros',
        '-fexceptions',
        '-ferror-limit=10000',
        '-DNDEBUG',
        '-std=c++11',
        '-xc++',
        '-I/usr/lib/',
        '-I/usr/src/googletest/googletest/libgtest.a',
        '-I/usr/src/googletest/googletest/libgtest_main.a',
        '-isystem /usr/src/googletest/googletest/libgtest.a',
        '-isystem /usr/src/googletest/googletest/libgtest_main.a',
        '-I/usr/include/'
        ]

As you can see I tried linking the libgtest.a to no avail. What am I doing wrong?


Solution

  • My problem was that in the /usr/include there was a gmock and a gtest folder that was an old version that did not have MOCK_METHOD but MOCK_METHOD0, ... 1, etc. That was the version Clang would give errors against, but my Bazel WORKSPACE file pulled gtest from the Github repo so that's why it compiled correctly.