strange compiler error 'in' MSVC++ functional template
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: strange compiler error 'in' MSVC++ functional template

  1. #1
    Join Date
    Mar 2012
    Posts
    2

    strange compiler error 'in' MSVC++ functional template

    Hi all, I'm working on a good sized project and after the latest code updates, I'm getting a compiler error the source of which is difficult to interpret:

    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2143: syntax error : missing ')' before '&'
    1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1083) : see reference to class template instantiation 'std::tr1::function<_Fty>' being compiled


    It's actually one of 19 errors from the same file (functional).


    This is the code (microsoft's code) at that line of the first error:

    void swap(_Myt& _Right)
    { // swap with _Right
    this->_Swap(_Right);
    }


    This happens when compiling a .cpp file that does not appear to use std::tr1::function or anything related to it. In fact, the code changes I made recently were not to the .cpp file that fails compilation due to this error. Typically, I can search the 'net and find a solution but this one has me stumped.

    It would appear that the compiler doesn't understand what a _Myt or _Fty type is. That makes two of us, but it IS defined above in the 'functional' file:

    template<class _Fty>
    class function
    : public _Get_function_impl<_Fty>::_Type
    { // wrapper for callable objects
    public:
    typedef function<_Fty> _Myt;

    Unfortunately, I can't post example code because the entirety of my project is too big to post and the compiler isn't pointing to any particular file of my project. Any help in getting started down the path of finding where the problem is would be fantastic. Here are the rest of the errors generated:



    Code:
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2143: syntax error : missing ')' before '&'
    1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1083) : see reference to class template instantiation 'std::tr1::function<_Fty>' being compiled
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2143: syntax error : missing ';' before '&'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2182: '_Myt' : illegal use of type 'void'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2377: 'std::tr1::function<_Fty>::_Myt' : redefinition; typedef cannot be overloaded with any other symbol
    1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(953) : see declaration of 'std::tr1::function<_Fty>::_Myt'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2143: syntax error : missing ';' before '<<'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1049) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1050) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : warning C4002: too many actual parameters for macro 'swap'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2143: syntax error : missing ')' before '&'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2143: syntax error : missing ';' before '&'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2182: 'function<_Fty>' : illegal use of type 'void'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2936: 'std::tr1::function<_Fty>' : template-class-id redefined as a global data variable
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2143: syntax error : missing ';' before '<<'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1087) : error C2065: '_Fty' : undeclared identifier
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1094) : error C2065: '_Fty' : undeclared identifier
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1095) : error C2143: syntax error : missing ';' before '{'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\functional(1095) : error C2447: '{' : missing function header (old-style formal list?)

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,315

    Re: strange compiler error 'in' MSVC++ functional template

    Have you tried reducing your own code to see if some part of it results in the same error? If you can narrow it down sufficiently to a reproducible example that can be posted here, it would be easier to help you fix the problem (or submit a bug report to Microsoft, if it really is a bug with the implementation).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,544

    Re: strange compiler error 'in' MSVC++ functional template

    I haven't had this particular error with the STL but I've had similar. I've usually found that the error involves wrong brackets (usually a missing } in my case!) some where in my own code. IMO I would re check the latest changes you're made to your code and examine closely for unmatched brackets.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Mar 2012
    Posts
    2

    Re: strange compiler error 'in' MSVC++ functional template

    Thank you, amazingly fast replies here.

    After going through and reducing the cpp file that it was working on when the error was generated to nothing, I found that one of the files that the cpp file included had this line:

    #define swap(x) (x<<8)|(x>>8)

    commenting this line out or renaming swap to something else fixes the problem. What might have happened is some other part of my code used a new section of STL. This new section of STL has swap defined as in the OP in a class template, so when the compiler arrived to my swap define macro in a header file, it threw some voodoo monkeywrench into the mix.

    I would expect a redefinition error, but am happy to be going again, thank you!

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,966

    Re: strange compiler error 'in' MSVC++ functional template

    there's a reason #define's can be terribly annoying... they're always in the global space, and they can confuse the compiler (and you) when those defines start interfering with templates.

    if you need defines yourself, it's a good idea to get into a habit of naming them in such a way that they can't possibly ever mess up library/API names. It also makes it clear in your code when you're using a define, but yes, it can mean your code may not 'look' as pretty.

    It's also not usually a good idea to include your own headers BEFORE library/api headers because of that, even though when templates get into the mix, this still doesn't give any guarantees.

  6. #6
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,014

    Re: strange compiler error 'in' MSVC++ functional template

    Quote Originally Posted by cuisinart View Post
    I would expect a redefinition error...
    Well, you're very wrong, because macros don't follow C++ syntax rules at all. A better way to look at macros is as glorified copy-pasting.
    See Why should I use inline functions instead of plain old #define macros?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,966

    Re: strange compiler error 'in' MSVC++ functional template

    You would have gotten a redefinition error it it was indeed a matter of redefinition.

    Here it's a matter of a #define getting 'substituded' in a template and resulting in "preprocessed" code that makes no sense.

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

This is a CodeGuru survey question.


Featured


HTML5 Development Center