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 7977375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:10:46+00:00 2026-06-04T09:10:46+00:00

I’m having an interesting issue with gcc 4.5.2. The following code #include<thread> #include<iostream> using

  • 0

I’m having an interesting issue with gcc 4.5.2. The following code

#include<thread>
#include<iostream>

using std::cout;
void foo(int a){
    cout<<a;
}

template <typename T>
void goo(void (*fn)(T),T c){
    fn(c);
}

int main(void)
{
    std::thread TH;
    void (*ptr)(int)=foo;
    TH= std::thread(goo<int>,ptr,1);
    TH.join();

    return 0;
}

.. will not compile on gcc 4.5.2 with error: cannot bind ‘void(void (*)(int), int)’ lvalue to ‘void (&&)(void (*)(int), int)’ followed by the second error initializing argument 1 of ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void(void (*)(int), int), _Args = {void (*&)(int), int}]’

However, this code does compile when the template is removed, and it also does compile with gcc 4.7.0 (with template in place).

Even if this is a compiler issue, could somebody please explain what such an error means? I would be happy to find a way to do the binding (even if this is, say, automatic in gcc 4.7).

  • 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-04T09:10:47+00:00Added an answer on June 4, 2026 at 9:10 am

    You stumbled upon two bugs.

    The first bug in GCC is that during the “perfect forwarding”-value category deduction, it thinks that goo<int> is an rvalue. But goo<int> is actually an lvalue. So instead of deducing _Callable to void(void (*)(int), int), it should have deduced it to void(&)(void (*)(int), int). Then reference collapsing would have yielded that lvalue reference as parameter type, instead of void(&&)(void (*)(int), int) like it incorrectly does with your GCC version.

    During the actual initialization of the parameter, it also incorrectly rejects initialization of rvalue reference parameter by the function lvalue (I don’t remember what the state of the working draft was when GCC4.5 was released – but possibly the draft had it ill-formed back then). For function type expressions, the Standard allows to initialize an rvalue reference to function type with an lvalue of function type.

    Resolving a template id to a function lvalue is quite convoluted, so it doesn’t surprise me GCC got it wrong (see http://llvm.org/bugs/show_bug.cgi?id=7505 and http://llvm.org/bugs/show_bug.cgi?id=7505 for two examples of how many rules interact for seemingly simple things).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.