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

Expected primary-expression before decltype CROW_MIDDLEWARES #365

Closed
Iuliean opened this issue Mar 18, 2022 · 6 comments
Closed

Expected primary-expression before decltype CROW_MIDDLEWARES #365

Iuliean opened this issue Mar 18, 2022 · 6 comments
Labels
question Issue can be closed by providing information

Comments

@Iuliean
Copy link
Contributor

Iuliean commented Mar 18, 2022

    template<unsigned N, const char(&url)[N], typename M, typename Func>
    void add_route (crow::HTTPMethod&& method, Func f)
    {
        this->app.route<crow::black_magic::get_parameter_tag(url)>(url)
            .CROW_MIDDLEWARES(this->app, M).methods(method)(f);
    }

The above mentioned code gives me these errors

In file included from ../dependencies/includes/Crow/include/crow.h:25,
                 from site.h:2,
                 from app.h:2,
                 from app.cpp:1:
site.h: In member function ‘void Site::add_route(crow::HTTPMethod&&, Func)’:
../dependencies/includes/Crow/include/crow/app.h:32:48: error: expected primary-expression before ‘decltype’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~~~~~~
../dependencies/includes/Crow/include/crow/app.h:32:48: note: in definition of macro ‘CROW_MIDDLEWARES’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~
../dependencies/includes/Crow/include/crow/app.h:32:48: error: expected ‘;’ before ‘decltype’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~~~~~~
../dependencies/includes/Crow/include/crow/app.h:32:48: note: in definition of macro ‘CROW_MIDDLEWARES’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~

i am calling the function like this this->add_route<sizeof(str), str, Authentificator>(crow::HTTPMethod::GET, [](){return "lol";});
and authentificator is defined like this

struct Authentificator : crow::ILocalMiddleware
{
    struct context{};

    void before_handle()
    {
        CROW_LOG_DEBUG << "keek";
    }

    void after_handle()
    {
        CROW_LOG_DEBUG << "lol";
    }
};
@dranikpg
Copy link
Member

Hi! Currently CROW_MIDDLEWARES has to be used in the last place 😓

.methods(method) .CROW_MIDDLEWARES(this->app, M)(f)

should do the job

@The-EDev The-EDev added the question Issue can be closed by providing information label Mar 18, 2022
@Iuliean
Copy link
Contributor Author

Iuliean commented Mar 18, 2022

i've tried that too and it doesnt work

  template<unsigned N, const char(&url)[N], typename M, typename Func>
    void add_route (crow::HTTPMethod&& method, Func f)
    {
        this->app.route<crow::black_magic::get_parameter_tag(url)>(url).methods(method)
            .CROW_MIDDLEWARES(this->app, M)(f);
    }
make[1]: Entering directory '/home/iulian/development/PiThermostatCPP/src'
arm-linux-gnueabihf-g++ -c -o /home/iulian/development/PiThermostatCPP/intermediates/release/app.o app.cpp -I../dependencies/includes/ -I../dependencies/includes/Crow/include/ -I../dependencies/includes/WiringPi/wiringPi/ -O3
In file included from ../dependencies/includes/Crow/include/crow.h:25,
                 from site.h:2,
                 from app.h:2,
                 from app.cpp:1:
site.h: In member function ‘void Site::add_route(crow::HTTPMethod&&, Func)’:
../dependencies/includes/Crow/include/crow/app.h:32:48: error: expected primary-expression before ‘decltype’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~~~~~~
../dependencies/includes/Crow/include/crow/app.h:32:48: note: in definition of macro ‘CROW_MIDDLEWARES’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~
../dependencies/includes/Crow/include/crow/app.h:32:48: error: expected ‘;’ before ‘decltype’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~~~~~~
../dependencies/includes/Crow/include/crow/app.h:32:48: note: in definition of macro ‘CROW_MIDDLEWARES’
   32 | #define CROW_MIDDLEWARES(app, ...) middlewares<decltype(app), __VA_ARGS__>()
      |                                                ^~~~~~~~
make[1]: *** [Makefile:14: /home/iulian/development/PiThermostatCPP/intermediates/release/app.o] Error 1
make[1]: Leaving directory '/home/iulian/development/PiThermostatCPP/src'
make: *** [Makefile:45: thermostat] Error 2

@dranikpg
Copy link
Member

dranikpg commented Mar 19, 2022

This code should work (clang13 / g++11 both swallow it). Note the template before middlwares()

template<unsigned N, const char(&url)[N], typename M, typename Func>
void add_route(crow::HTTPMethod method, Func f) {
  app.route<crow::black_magic::get_parameter_tag(url)>(url)
    .methods(method)
    .template middlewares<decltype(app), M>()(f);
}

Unfortunately, Crow uses inconvenient constexpr char arrays for paths and the error becomes hard to decrypt 😀 . Now that your app.route() depends on your template arguments, .middlewares<> becomes a dependent template name and has to be prefixed with template.

Btw, looks a little less confusing with macros.

CROW_ROUTE(app, url)
    .methods(method)
    .template CROW_MIDDLEWARES(app, M)(f);

Hope that helps

@dranikpg
Copy link
Member

I'll think about the implications of adding the template keyword to CROW_MIDDLEWARES. While it might technically be obsolete at times, it shouldn't break anything and would resolve such issues

@Iuliean
Copy link
Contributor Author

Iuliean commented Mar 19, 2022

yes that worked thanks for the help

@The-EDev
Copy link
Member

Closing this issue as the initial problem was solved. See #369 for adding template to the macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issue can be closed by providing information
Projects
None yet
Development

No branches or pull requests

3 participants