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

  • Home
  • SEARCH
  • 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 6597009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:09:12+00:00 2026-05-25T18:09:12+00:00

UPDATE the belowmentioned bug is fixed in VS2012, and noncopyable works as epected This

  • 0

UPDATE the belowmentioned bug is fixed in VS2012, and noncopyable works as epected

This is both a question and a way to provide information / warn others so they don’t fall into the same trap as I did: it seems that using a noncopyable base class (like the one in boost) has no effect in exported classes when using the MS compiler. This is a known bug to MS but I doubt there are a lot of programmers that know of it. As one can imagine, this can produce extremely nasty bugs because it allows writing code that should not even compile. Example (code for noncopyable class here🙂

a typical header file in a dll project, compile with /D EXPORT_IT:

#ifdef EXPORT_IT
  #define mydll __declspec( dllexport )
#else
  #define mydll __declspec( dllimport )
#endif    

class mydll CantCopyMe : private noncopyable
{
public:
  CantCopyMe();
  ~CantCopyMe();
};

mydll CantCopyMe MakeIt();

the source file:

#include <iostream>

CantCopyMe::CantCopyMe()
{
  std::cout << "constructor" << std::endl;
}

CantCopyMe::~CantCopyMe()
{
  std::cout << "destructor" << std::endl;
}

CantCopyMe MakeIt()
{
  CantCopyMe x;
  return x; //oops... this sould not compile nor link but it does
}

the application:

int main()
{
  CantCopyMe x( MakeIt() );
}

the output:

constructor
destructor
destructor

1 constructor, 2 destructors called. Imagine the problems when the class effectively contains resources.

edit
usage cases that do compile but should not:

CantCopyMe MakeIt()
{
  CantCopyMe x;
  return x;
}

void DoIt( CantCopyMe x )
{
  x.Foo();
}

void SomeFun()
{
  CantCopyMe x;
  DoIt( x );
}

other cases:
CantCopyMe MakeIt()
{
return CantCopyMe(); //fatal error C1001
}

CantCopyMe GenerateIt()
{
  CantCopyMe x;
  return x;
}

CantCopyMe MakeIt()
{
  return GenerateIt(); //fatal error C1001
}

CantCopyMe MakeIt()
{
  CantCopyMe x;
  return CantCopyMe( x ); //fatal error C1001 + cl crashes
}

void DoSomething()
{
  CantCopyMe x;
  CantCopyMe y = x; //fatal error C1001 + cl crashes
}  

Questions:

  1. The KB article mentions a fix in an upcoming release. Can anyone check if this is fixed in VS2010 already (or possibly with a Visual Studio 11 preview)?

  2. Is there any workaround to trigger any kind of error? I tried (ab)using the fact that writing return CantCopyMe() triggers an internal compiler error but, I couldn’t find a way to conditionally trigger it only when compiling a function like MakeIt above. Putting static_assert in the noncopyable’s copy constructor also doesn’t cut it since the compiler will always compile it even if it doesn’t get invoked.

  • 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-05-25T18:09:12+00:00Added an answer on May 25, 2026 at 6:09 pm

    To answer 1 (for VS2010), I just tried it in VS2010 (with SP1) and it compiles just fine, which means it has not been fixed. Unfortunately I do not have 2011 to test

    To 2. I guess one way to do it would be to:

    • no longer derive from noncopyable
    • declare the copy ctor and assignment operator as private in CantCopyMe without providing an implementation)
    class CantCopyMe 
    {
    public:
       //omitted for brevity...
    private:
        CantCopyMe( const CantCopyMe& );
        const CantCopyMe& operator=( const CantCopyMe& );
    };
    

    With this done you avoided the dangerous situations you describe and it should work with VS2008 also. And you solve the problem in the right place, that is in the non-copyable class declaration.

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

Sidebar

Related Questions

Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Please read this question in the context of design principles, elegance, expression of
UPDATE This is an old question for an old version of Xcode. It turned
Update: With iPhone OS 3.0+, the whole UIImagePickerController API has changed. This question and
Update: This issue was fixed in Redemption 5.2 : Previously, named MAPI properties in
UPDATE: I made a mistake in my debugging - this question is not relavent
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
UPDATE: I've completely changed the question because in reality, I'm having a really hard
Update 2018 TL;DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math Original question I need to have a

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.