locked
Bug: VS2012 Update2: delegate declarations cancel out preceding namespace inclusions

    Question

  • Hello,

    This compiles:

    ------class1.cpp---------------

    namespace X {
     class CX {};
    }

    namespace Y {

    using namespace X;

    //public delegate void D();
    public ref class CY sealed
    {
     CX x;
    };

    }

     -----------------------

    Uncomment the delegate declaration and it no longer compiles "class1.cpp(12): error C2146: syntax error : missing ';' before identifier 'x'". Turns out declaring delegate cancels out any namespace inclusions that happened prior in that namespace. In the example below, compiler no longer "sees" "using namespace X" when delegate is declared. If, after declaring the delegate, you revert CX to full form "X::CX", it starts to compile again.

    Sample project with the repro: http://sdrv.ms/118FP1K

    This is extremely annoying. Is this known? Is there a fix available?

    Thanks!

    Monday, April 15, 2013 2:44 AM

Answers

All replies

  • Hello,

     

    Thanks for your feedback, I will involve more experts to investigate it.

     

    Best regards,

    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mythanar Wednesday, April 17, 2013 6:23 AM
    Tuesday, April 16, 2013 7:05 AM
  • Thanks!
    Wednesday, April 17, 2013 6:23 AM
  • Hi there,

    try this code, is ok:

    namespace X {
    	class CX {};
    }
    
    namespace Y {
    
    using namespace X;
    
    
    public ref class CY sealed
    {
    	
    	CX x;
    };
    
    public delegate void D();
    }

    Regards,

    Jenny

     
    Thursday, April 18, 2013 9:45 AM
  • Hi Jenny,

    The code you provided works, but does not solve the problem. I've provided the minimal repro to illustrate the problem. In the real code, class CY uses D as the type for its events, so declaring it after that class is not an option.

    There is a workaround - just use fully-specified namespace names everywhere. But this is annoying and I want to make sure this is on VC++ team radar for a fix.

    Sunday, May 19, 2013 3:25 AM