Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile failed #2

Closed
sequoiar opened this issue Oct 20, 2021 · 5 comments
Closed

compile failed #2

sequoiar opened this issue Oct 20, 2021 · 5 comments
Assignees

Comments

@sequoiar
Copy link

sequoiar commented Oct 20, 2021

the failure message is like below

command_interface.hpp:153:35: error: 'x6' was not declared in this scope
       return err_type_args(typeid(x##n).name(), n); \
                                   ^
/opt/include/boost/preprocessor/repetition/limits/repeat_256.hpp:282:62: note: in expansion of macro 'CAST'
 # define BOOST_PP_REPEAT_2_7(m, d) BOOST_PP_REPEAT_2_6(m, d) m(3, 6,
@chrisaycock
Copy link
Member

chrisaycock commented Oct 20, 2021

Could you show me the type signature of the function/command you registered?

@chrisaycock chrisaycock self-assigned this Oct 20, 2021
@sequoiar
Copy link
Author

check below cmd signature
std::string cmd_say(std::string msg);

@chrisaycock
Copy link
Member

I am unable to reproduce the error.

#include <iostream>
#include "command_interface.hpp"

class SampleInterface : public CommandInterface {
  std::string cmd_say(std::string msg) {
    return "Received: " + msg;
  }

  void register_commands() override {
    register_command(&SampleInterface::cmd_say, "say", "Repeat a string");
  }
};

int main() {
  SampleInterface si;
  std::string text;
  std::cout << ">>> ";
  while (std::getline(std::cin, text)) {
    std::cout << si.eval(text) << std::endl << std::endl;
    std::cout << ">>> ";
  }
  return 0;
}

It compiles and runs.

>>> help
say   Repeat a string
help  Show this help

>>> say SomeText 
Received: SomeText

Are you able to show your entire code? Specifically, are you able to provide a minimal reproducible example?

Also, which compiler are you using? Which versions of C++ and Boost?

@sequoiar
Copy link
Author

sequoiar commented Oct 23, 2021

cli.h :


#include <sstream>
#include <string>
#include "command_interface.hpp"

class cli: public CommandInterface
{
    public:
        std::string cmd_say(std::string msg);

        /// @brief overrid command-interface
        virtual void register_commands();

};

cli.cpp:


#include <sstream>
#include <iostream>
#include "cli.h"

using namespace std;

std::string cli::cmd_say(std::string msg) {
    std::ostringstream ss;
    ss << "Hi Sir, This is " << msg << std::endl;
    return ss.str();
}

/// @brief register commands
void cli::register_commands()
{
    register_command(&cli::cmd_say,        "say",        "Say hello words");
}

int main(int argc, char *argv[]) {
    auto cmdline = cli{};

    std::string text;
        cout << "<<< ";
        while (getline(cin, text))
        {
            cout << cmdline.eval(text) << endl;
            cout <<"<<< ";
        }

        return 0;
}

compile with c++11 and boost-1.77.0


g++ -std=c++11 -I/opt/include/ -I../src/command-interface/ cli.cpp -o cli.cxxbin

compile error:


nsion of macro 'BOOST_PP_REPEAT'
 BOOST_PP_REPEAT(8, CALL_COMMAND, ~)
 ^~~~~~~~~~~~~~~
../src/command-interface/command_interface.hpp:172:89: error: 'x6' was not declared in this scope
     return boost::lexical_cast<std::string>((obj->*func)( BOOST_PP_REPEAT(n, REP_COMMA, x) )); \
                                                                                         ^
../src/command-interface/command_interface.hpp:144:52: note: in definition of macro 'REP_COMMA'
 #define REP_COMMA(z, n, text) BOOST_PP_COMMA_IF(n) text##n

@chrisaycock
Copy link
Member

chrisaycock commented Oct 23, 2021

Ah, the issue was C++11. I have pushed a fix that now compiles your code under C++11.

$ c++ -std=c++11 cli.cpp 
$ ./a.out 
<<< say GitHub
Hi Sir, This is GitHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants