CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: Compiler error 3848

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Compiler error 3848

    I'm updating some code that previously built okay with VS2005:-

    Code:
    struct id_compare
    {
    	bool operator()(const boost::shared_ptr<Playlist>& p1, const boost::shared_ptr<Playlist>& p2)
    	{
    		return p1->id () < p2->id ();
    	}
    };
    
    
    typedef std::set<boost::shared_ptr<Playlist> > List;
    typedef std::set<boost::shared_ptr<Playlist>, id_compare> IDSortedList;
    
    
    static void
    get_id_sorted_playlists (const List& playlists, IDSortedList& id_sorted_playlists)
    {
    	for (List::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
    		id_sorted_playlists.insert(*i); // <--- COMPILER ERROR C3848 HERE !!!!
    	}
    }
    but VS2019 gives me this error at the above line:-

    error C3848: expression having type 'const id_compare' would lose some const-volatile qualifiers in order to call 'bool id_compare:perator ()(const boost::shared_ptr<ARDOUR::Playlist> &,const boost::shared_ptr<ARDOUR::Playlist> &)'
    message : see reference to function template instantiation 'std::_Tree_find_result<std::_Tree_node<boost::shared_ptr<ARDOUR::Playlist>,std::_Default_allocator_traits<_Alloc>::void_pointer> *> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Find_lower_bound<_Key>(const _Keyty &) const' being compiled
    with
    [
    _Alloc=std::allocator<boost::shared_ptr<ARDOUR::Playlist>>,
    _Kty=boost::shared_ptr<ARDOUR::Playlist>,
    _Pr=id_compare,
    _Key=boost::shared_ptr<ARDOUR::Playlist>,
    _Keyty=boost::shared_ptr<ARDOUR::Playlist>
    ]
    Can anyone see a problem with the above code? Or is it likely to be some kind of issue with the supplier (Playlist) object?
    "A problem well stated is a problem half solved. - Charles F. Kettering

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,425

    Re: Compiler error 3848

    I suspect that .insert() doesn't want a const argument. Try making i ::iterator instead of ::const_iterator. Also, as .begin()/.end() are used rather than .cbegin()/.cend(), then the type should be ::iterator.

    There's lots of things that VS2005 compiled (as C++98!) that weren't right but weren't complained about! Back then VS was very lax about what was correct and what wasn't! This changed when they re-wrote there compiler front-end. VS is much more standard compliant now.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.8.6)

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    Thanks 2kaud - I tried removing const and also changing to cbegin() / cend() etc but nothing seemed to help.

    For testing purposes I've now changed to very simple types but with a simple list of ints, I'm now seeing compiler error C2664 at the same line :-

    Code:
    typedef std::list<int> my_ints;
    
    	struct id_compare
    	{
    		bool operator()(const boost::shared_ptr<int>& p1, const boost::shared_ptr<int>& p2)
    		{
    			return p1 < p2;
    		}
    	};
    
    	typedef std::set<boost::shared_ptr<my_ints> > List;
    	typedef std::set<boost::shared_ptr<my_ints>, id_compare> IDSortedList;
    
    	static void
    	get_id_sorted_ints(my_ints& ints, IDSortedList& id_sorted_ints)
    	{
    		for (my_ints::iterator i = ints.begin(); i != ints.end(); ++i) {
    			id_sorted_ints.insert(*i); // <--- COMPILE ERROR 2664 NOW !!!!
    		}
    	}
    There's something I'm just not seeing here...
    "A problem well stated is a problem half solved. - Charles F. Kettering

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    I'm not sure what's happening in the original code - but in my simplified version...

    Code:
    id_sorted_ints.insert(*i);
    insert() seems to be expecting a std::initializer_list rather than an int

    So how should I add an int to the set of ints
    "A problem well stated is a problem half solved. - Charles F. Kettering

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    Going back to the original problem, I just modified the code and realised something...

    Code:
    	static void
    	get_id_sorted_playlists (const List& playlists, IDSortedList& id_sorted_playlists)
    	{
    		for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
    
    			const boost::shared_ptr<Playlist> xx = *i;
    			boost::shared_ptr<Playlist> yy = *i;
    
    			id_sorted_playlists.insert(xx); // <--- FAILS TO COMPILE !!!
    
    			id_sorted_playlists.insert(yy); // <--- ALSO FAILS TO COMPILE !!!
    	}
    As you can see, I can allocate *i to either a const or non-const boost::shared_ptr<Playlist> - BUT - neither of them can subsequently get passed to IDSortedList::insert() (i.e. std::set::insert() rejects them both). Furthermore... if I remove the various const modifiers (in the original code) that doesn't help. This is starting to look like an incompatibility between boost::shared_ptr and VS2019's std::set
    Last edited by John E; January 21st, 2021 at 12:25 PM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,425

    Re: Compiler error 3848

    Re post #3.

    You're not inserting an int to a set of int. The set isn't a set of int - but a set of shared_ptr<list<int>> - which is a very different animal!

    What's with all the shared_ptr??

    The id_comp() function isn't right either - as the 2 args are actually list<int>, not int. Don't forget that IDSortedList is at it's basics a set of list<int> - so it maintains unique ::list, so the compare has to compare each list and return true/false if list p1 < list p2 - not int p1 < int p2.

    The .insert() needs to insert a ::list<int> type, not an int.

    How this compiled originally, I don't know.

    Something is not right.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.8.6)

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,425

    Re: Compiler error 3848

    Just a quick question. You are using the latest version of boost when compiling with VS2019 - not the old version used with VS005?

    I don't know/use boost, but looking again at the code in post #3

    Code:
    typedef std::set<boost::shared_ptr<my_ints>, id_compare> IDSortedList;
    Isn't IDSortedList a set of shared pointers? Therefore shouldn't the insert be a shared pointer - or does boost::shared_ptr have some special overload that allows a value to be converted to a ptr?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.8.6)

  8. #8
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    Quote Originally Posted by 2kaud View Post
    I don't know/use boost, but looking again at the code in post #3

    Code:
    typedef std::set<boost::shared_ptr<my_ints>, id_compare> IDSortedList;
    Isn't IDSortedList a set of shared pointers? Therefore shouldn't the insert be a shared pointer - or does boost::shared_ptr have some special overload that allows a value to be converted to a ptr?
    Yesterday I tried removing the Playlist elements and replacing them with a simpler type (int) - but I was quite tired by that stage! I did make it work eventually - but only by removing the boost stuff...

    Quote Originally Posted by 2kaud View Post
    Just a quick question. You are using the latest version of boost when compiling with VS2019 - not the old version used with VS005?
    Yes - it's still the older version but it's fairly recent (I'm using v1.71 and the latest is v1.74). I guess it might be worthwhile updating though. Thanks for the suggestion...
    "A problem well stated is a problem half solved. - Charles F. Kettering

  9. #9
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    I found a list of useful solutions at Stackoverflow.

    Solution #4 is the older version that uses a struct (essentially what used to work okay with VS2005). And solution #5 uses std::integral_constant to create a struct somehow from a boolean function. Bingo!! Solution #5 works for VS2019 !!!

    So I'm starting to think that for VS2019, either the older method has been restricted now to only work with basic types - or else it's just plain broken!!
    "A problem well stated is a problem half solved. - Charles F. Kettering

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,425

    Re: Compiler error 3848

    Thanks for update. I remember this mess now. We went through the conversion from C++98 with VS2012/2013. Nightmare!

    re the set comparator. It needs a type (eh!) for the templated parameter. That's why std::integral_constant works as it wraps the value into a templated struct and as a type that can then be used.

    Interestingly (???), if you define a lambda you can use the lambda name - but you can't directly use a lambda.

    PS Re the original operator() in id_compare, did you try making operator() const?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.8.6)

  11. #11
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    Quote Originally Posted by 2kaud View Post
    PS Re the original operator() in id_compare, did you try making operator() const?
    I just gave that a try here but it still gives me C3848


    Quote Originally Posted by 2kaud View Post
    re the set comparator. It needs a type (eh!) for the templated parameter. That's why std::integral_constant works as it wraps the value into a templated struct and as a type that can then be used.
    Is that something that needs to get fed back to Microsoft somehow?
    "A problem well stated is a problem half solved. - Charles F. Kettering

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,455

    Re: Compiler error 3848

    Quote Originally Posted by John E View Post
    Is that something that needs to get fed back to Microsoft somehow?
    Probably the least painful approach is to incrementally keep production code to the current version or at least cuurent minus 1. Yeah, every few years you have to feel a little pain getting your old code to conform to a new compiler (that is even more c++ standards compliant), but at least it's a little pain, not the pain of converting 15 or 25 year old code.

  13. #13
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,425

    Re: Compiler error 3848

    Is that something that needs to get fed back to Microsoft somehow?
    It's the standard - not MS AFAIK.

    The standard changes - and there have been massive changes since C++98. Getting a C++98 solution to compile as C++17 can be an utter nightmare! As Arjay suggests, the least painful way is to keep fairly up-to-date with the compiler version and compile against this. Updating from say C++14 to C++17/20 is no where near as painful as doing it from C++98.

    IMO, if you're got code that hasn't compiled OK with at least VS2013, then you're probably going to have issues compiling as VS2019. I'd be wanting to 'check/update' all the code so that it's OK with VS2019. As I said, we went through this pain when we updated to VS2012/13 - and it wasn't nice. Thankfully now updating to the next version seems to be fairly painless.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.8.6)

  14. #14
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,695

    Re: Compiler error 3848

    Up to now I think I've updated around 70 support projects which I can now compile with VS2019 - but there've been very few show stoppers. The only previous one I remember was realising that the __asm keyword isn't supported for 64-nit builds (tho' I guess that would've been true, even with my previous version of VC++)
    "A problem well stated is a problem half solved. - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)