Home Dashboard Directory Help
Search

Class Wizard and class view does not detect namespaces changes in configurations by Sheng Jiang 蒋晟


Status: 

Active


2
0
Sign in
to vote
Type: Bug
ID: 543019
Opened: 3/18/2010 1:14:11 PM
Access Restriction: Public
1
Workaround(s)
view
1
User(s) can reproduce this bug

Description

The parser for namespaces does not seem to be sensitive to conditional declarations
For example, if a class is in namespace A in debug build and in namespace B in release build, the class view and the class wizard thinks the class is in namespace B even in debug build. Intellisense detects the namespace change correctly.
Details
Sign in to post a comment.
Posted by David Carr on 3/9/2012 at 3:02 PM
Vinny, MS, the C++ team, and the VS Product Team,

It isn't good at all that the Class Wizard is unable to locate classes which are enclosed within a namespace. It renders Class Wizard useless.

It would be responsive and responsible if MS would state in what version of Visual Studio this bug will be fixed.

Regards,
David
Posted by Microsoft on 4/1/2010 at 4:45 PM
In that case, you can simplify step 1 of the work-around to not be dependent on the _DEBUG macro:

    #define BEGIN_NAMESPACE_MFCIE namespace MFCIE {
    #define END_NAMESPACE_MFCIE }

Steps 2 and 3 would remain the same.
Posted by Microsoft on 4/1/2010 at 4:45 PM
In that case, you can simplify step 1 of the work-around to not be dependent on the _DEBUG macro:

    #define BEGIN_NAMESPACE_MFCIE namespace MFCIE {
    #define END_NAMESPACE_MFCIE }

Steps 2 and 3 would remain the same.
Posted by Microsoft on 4/1/2010 at 4:45 PM
In that case, you can simplify step 1 of the work-around to not be dependent on the _DEBUG macro:

    #define BEGIN_NAMESPACE_MFCIE namespace MFCIE {
    #define END_NAMESPACE_MFCIE }

Steps 2 and 3 would remain the same.
Posted by Microsoft on 4/1/2010 at 4:45 PM
In that case, you can simplify step 1 of the work-around to not be dependent on the _DEBUG macro:

    #define BEGIN_NAMESPACE_MFCIE namespace MFCIE {
    #define END_NAMESPACE_MFCIE }

Steps 2 and 3 would remain the same.
Posted by Microsoft on 4/1/2010 at 4:45 PM
In that case, you can simplify step 1 of the work-around to not be dependent on the _DEBUG macro:

    #define BEGIN_NAMESPACE_MFCIE namespace MFCIE {
    #define END_NAMESPACE_MFCIE }

Steps 2 and 3 would remain the same.
Posted by Sheng Jiang 蒋晟 on 4/1/2010 at 3:27 PM
Thanks, the conditional building is to get around the namespace issue in Class View and Class Wizard.
Posted by Microsoft on 4/1/2010 at 3:07 PM
Thank you for providing feedback regarding the behavior of the Class View and Class Wizard. Some of the behavior you describe is 'By Design', as the C++ Tag Parser, which is used to populate the Class View and the Class Wizard, does not honor preprocessor conditional directives. http://blogs.msdn.com/vcblog/archive/2009/08/12/tag-parsing-c.aspx describes this design in more detail.

I'm not sure why you would want to have code contained in different namespaces based on preprocessor defines, but you could work-around your issue as follows:

1. Declare two macros to be used to open and close the MFCIE namespace:

    #ifndef _DEBUG
    #define BEGIN_NAMESPACE_MFCIE namespace MFCIE {
    #else
    #define BEGIN_NAMESPACE_MFCIE
    #endif

    #ifndef _DEBUG
    #define END_NAMESPACE_MFCIE }
    #else
    #define END_NAMESPACE_MFCIE
    #endif

2. Use these BEGIN_NAMESPACE_MFCIE and END_NAMESPACE_MFCIE macros to wrap whatever code you would conditionally like to appear in the MFCIE namespace.

3. Create a Hint File called 'cpp.hint' in the directory where your project is located with the following content:

    #define BEGIN_NAMESPACE_MFCIE
    #define END_NAMESPACE_MFCIE

Note: Hint Files are documented at: http://msdn.microsoft.com/en-us/library/dd997977(VS.100).aspx

This will result in Class View and Class Wizard ignoring the MFCIE namespace and always display the contents as if they were in the global namespace.

The fact that the Class Wizard does not show classes that are declared within a namespace is a bug in the current implementation. Unfortunately, it is too late to fix this issue in the RTM release of Visual Studio 2101, but we will consider fixing it in a future release.

Vinny Romano
Visual C++ Team
Posted by Microsoft on 3/18/2010 at 7:00 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you
Sign in to post a workaround.
Posted by Sheng Jiang 蒋晟 on 3/18/2010 at 1:19 PM
remove namespace conditions in the header file
in the cpp files, enclose their #include statements in #ifndef blocks
for example, replace
#include "stdafx.h"

#include "mfcie.h"

#include "MainFrm.h"
#include "mfcieDoc.h"
#include "mfcieVw.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifndef _DEBUG
namespace MFCIE
{
#endif


with
#include "stdafx.h"

#ifndef _DEBUG
namespace MFCIE
{
#endif

#include "mfcie.h"

#include "MainFrm.h"
#include "mfcieDoc.h"
#include "mfcieVw.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


this will make the MFC classes defined in header files appear in the global namespace for the class viewer and class wizard.

classes defined in cpp files such as CAboutDlg would still appear in the wrong namespace and would be invisible in the class wizard.