Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:50:03+00:00 2026-06-13T01:50:03+00:00

I had a function submitAsync which accepted a templated std::function as a parameter: template

  • 0

I had a function submitAsync which accepted a templated std::function as a parameter:

template <typename Ret, typename... Args>                                                                                                                                                     
Future<Ret> submitAsync(const function<Ret (Args...)> &func, Args&&... args);

However, implicit template argument deduction wasn’t working when passing a lambda (similar to the issue here, so I had to make a more generic function that accepted the function as a template parameter, to then pass it to the original function:

template <typename Func, typename... Args>
auto submitAsync(Func &&func, Args&&... args) -> // Line 82, where the strange error occurs
    Future<
        typename enable_if<
            is_convertible<
                Func, function<decltype(func(args...)) (Args...) >
            >::value ,  decltype(func(args...))
        >::type
    > {
    typedef decltype(func(args...)) ReturnType;
    return submitAsync<ReturnType, Args...>(function<ReturnType (Args...)>(func), forward<Args>(args)...);
}

This compiles fine with Clang, but with GCC returns the following error:

src/Scheduler.hpp: In substitution of ‘template<class Func, class ... Args> Future<typename std::enable_if<std::is_convertible<Func, std::function<decltype (func(MCServer::Scheduler::startThread::args ...))(Args ...)> >::value, decltype (func(args ...))>::type> MCServer::Scheduler::submitAsync(Func&&, Args&& ...) [with Func = int; Args = {}]’:
src/Scheduler.hpp:91:109:   required from ‘Future<typename std::enable_if<std::is_convertible<Func, std::function<decltype (func(MCServer::Scheduler::startThread::args ...))(Args ...)> >::value, decltype (func(args ...))>::type> MCServer::Scheduler::submitAsync(Func&&, Args&& ...) [with Func = MCServer::MinecraftServer::init()::<lambda()>&; Args = {}; typename std::enable_if<std::is_convertible<Func, std::function<decltype (func(MCServer::Scheduler::startThread::args ...))(Args ...)> >::value, decltype (func(args ...))>::type = int]’
src/MinecraftServer.cpp:237:37:   required from here
src/Scheduler.hpp:82:10: error: expansion pattern ‘#‘nontype_argument_pack’ not supported by dump_expr#<expression error>’ contains no argument packs

This shows firstly that the lines

return submitAsync<ReturnType, Args...>(function<ReturnType (Args...)>(func), forward<Args>(args)...); 

which should be calling submitAsync(const function<Ret (Args...)> &, Args&&...), is actually trying to call submitAsync(Func &&func, Args&&... args), which of course doesn’t work as the type of func being passed is int.
The last part of the error I also do not understand, expansion pattern ‘#‘nontype_argument_pack’ not supported by dump_expr#<expression error>’ contains no argument packs which could perhaps be a compiler bug (line 82 is the main part of the function’s signature, where I put a comment to mark it)?

Strangely enough, when I remove the explicit template parameters in the call to submitAsync, replacing this line:

return submitAsync<ReturnType, Args...>(function<ReturnType (Args...)>(func), forward<Args>(args)...);

with this:

return submitAsync(function<ReturnType (Args...)>(func), forward<Args>(args)...);

GCC compiles it correctly.
So, why is GCC calling the wrong function when the template arguments are specified, even though it works fine when allowed to deduce the arguments? And can anyone tell me what the strange error on line 82 is?

Edit: Forgot to mention, I’m using GCC 4.7.2

EDIT 2: solution and explanation here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:50:04+00:00Added an answer on June 13, 2026 at 1:50 am

    Upon further testing, I’ve realised that both Clang and GCC without explicit template parameters wasn’t actually working as I wished. In both cases, the function was just calling itself as the first function that fit the parameters. It was caused by the compiler deciding the submitAsync that takes the function as a template parameter was a better match than the one taking a const std::function&. It works fine now after changing that submitAsync to take the function by reference:

    template <typename Ret, typename... Args>
    Future<Ret> Scheduler::submitAsync(function<Ret (Args...)> func, Args&&... args)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a function which is pulling all the dates from database against each
I had a function in which I had to attach event on an element
I had a function below which stores distances from two locations using google maps
void spawn_enemies(vector<Enemy>& enemies) { I had that function, and it worked just fine to
So...say I had a function like this... int function( const char *c ) {
I have a javascript function in which if a user select future date then
The old JS SDK had a function called FB.ensureInit. The new SDK does not
Prior to C++11, if I had a function that operated on large objects, my
I had written a function to generate a word document by using the Office
I had only one function to Add another row to the table id=tblOtherParties and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.