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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:22:35+00:00 2026-06-17T04:22:35+00:00

Why does this fail to compile g++4.6 and g++4.7? I am trying to get

  • 0

Why does this fail to compile g++4.6 and g++4.7?
I am trying to get a mapping of string to thread specific storage.
I had something like this working in boost 1.48 I believe.
Actually, it is not related to the version of boost, but the flag -std=c++0x.
If that is not present it compiles. So, looking for interpretation of error and
how to work around it.

Thanks

#include <map>
#include <boost/thread/tss.hpp>
#include <boost/shared_ptr.hpp>

int main(int argc, char** argv) {
  typedef boost::thread_specific_ptr< int > Tss_int_ptr;
  typedef std::map< std::string, Tss_int_ptr > Tss_int_map_t;
  Tss_int_map_t tmap;
  return 0;
}

The error message follows.

g++-4.7 -g -std=c++0x -I"/home/someone/open_source/admin/install/boost_1_52_0/include" -c  ~/tmp/fail.cpp
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:65:0,
             from /usr/include/c++/4.7/bits/stl_tree.h:63,
             from /usr/include/c++/4.7/map:60,
             from /home/someone/tmp/fail.cpp:1:
/usr/include/c++/4.7/bits/stl_pair.h: In instantiation of ‘struct std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> >’:
/usr/include/c++/4.7/bits/stl_tree.h:133:12:   required from ‘struct std::_Rb_tree_node<std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> > >’
/usr/include/c++/4.7/bits/stl_tree.h:1082:4:   required from ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_erase(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type) [with _Key = std::basic_string<char>; _Val = std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> >; _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> > >; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> > >*]’
/usr/include/c++/4.7/bits/stl_tree.h:646:9:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::~_Rb_tree() [with _Key = std::basic_string<char>; _Val = std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> >; _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> > >; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> > >]’
/usr/include/c++/4.7/bits/stl_map.h:90:11:   required from here
/usr/include/c++/4.7/bits/stl_pair.h:119:17: error: ‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::basic_string<char>; _T2 = boost::thread_specific_ptr<int>; std::pair<_T1, _T2> = std::pair<const std::basic_string<char>, boost::thread_specific_ptr<int> >]’ declared to take const reference, but implicit declaration would take non-const
  • 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-17T04:22:36+00:00Added an answer on June 17, 2026 at 4:22 am

    thread_specific_ptr declares these members, in order to make the class non-copyable (note the non-const parameters):

    private:
        thread_specific_ptr(thread_specific_ptr&);
        thread_specific_ptr& operator=(thread_specific_ptr&);
    

    In C++03 std::pair does not have a copy constructor declared, so one is implicitly generated if needed by the program. A std::pair<X, thread_specific_ptr> is not copyable, because one of its members is not copyable, so if the implicit copy constructor was used it would be an error.

    In C++11 std::pair has a copy constructor, which is explicitly defaulted. It has the signature:

    pair(const pair&) = default;
    

    The compiler error is telling you that the implicitly-generated copy constructor would have this signature, because the thread_specific_ptr copy constructor signature takes a non-const reference:

    pair(pair&) = default;
    

    Because the defaulted constructor does not have the same signature as what would have be implicitly declared, the copy constructor is ill-formed.

    So in both cases the pair<X, thread_specific_ptr> is not copyable, but in C++11 the error is noticed sooner, even though you don’t try to copy the object.

    If boost::thread_specific_ptr used the normal C++11 idiom for making a class non-copyable the code would work:

    thread_specific_ptr(const thread_specific_ptr&) = delete;
    thread_specific_ptr& operator=(const thread_specific_ptr&) = delete;
    

    So I would report this as a bug to Boost. In C++11 mode the copy operations should be deleted.

    As a workaround you can wrap the type in your own type with deleted copy operations, then use that instead:

    template<typename T>
    struct TSS : boost::thread_specific_ptr<T>
    {
      TSS() = default;
      TSS(void (*f)(T*)) : boost::thread_specific_ptr<T>(f) { }
      TSS(const TSS&) = delete;
      TSS& operator=(const TSS&) = delete;
    };
    

    Now you can use this and your code will compile:

    typedef TSS< int > Tss_int_ptr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand why the following test does not fail. In this simplified
Why does this code fail to compile with VS 2005: #include <boost/bind.hpp> #include <boost/function.hpp>
Why does this fail to compile: int myVar = 0; myVar ? []()->void{} :
Why does this fail to compile with GCC 4.4? template<typename T> class A {
Why does this code fail to compile? double d ; int & i1 =
Why does this fail to compile? (g++-4.5) template < typename U > static void
Quite simply, why does this code fail to compile? public interface IWorld { }
Why does this first if compile well and the second fail? if(proceed) {int i;}
Why does this fail, it's supposed to be simple and work ? fisier.seekg(0, ios::end);
Why does this assertion fail? Assert.AreEqual( Color.Red, Color.FromArgb( Color.Red.A, Color.Red.R, Color.Red.G, Color.Red.B ) );

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.