BUG: Compiler Accepts Invalid Syntax: "class funcname()"

Last reviewed: July 22, 1997
Article ID: Q116171
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

The Microsoft C/C++ Compiler for MS-DOS, versions 8.0 and 8.0c, does not generate an error or warning when the C++ keyword "class" is used with a function for which a declaration has been provided.

RESOLUTION

The ambiguity of using the C++ keyword "class" with a declared function should be resolved. Either a class should be defined with a name that is different from the function or the "class" keyword should be removed from the function call.

When the C++ keyword "class" is used with a function for which a declaration has been provided, the C/C++ compiler for Windows NT, version 8.0, returns the following error message:

   error C2514: 'S' : class has no constructors

This is the correct behavior.

STATUS

Microsoft has confirmed this to be a bug in the C/C++ compiler for MS-DOS, versions 7.0, 8.0, and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This problem does not occur with the C/C++ 32-bit compiler, version 8.0 or version 9.0.

MORE INFORMATION

Suppose a function "func()" has been defined and declared within a single .CPP file. If func() is invoked later in the same file, the code runs as expected. However, if "class func()" is used, the func() function may run instead. Within this context the compiler should be capable of determining that a function call has not been requested because the term "class" appears before the term "func()". However, it does not.

You can use the following sample code to illustrate this problem:

Sample Code

/* Compile options needed: none
*/
   #include <stdio.h>

   static int call_count = 0; // Number of calls to the function

   short S()   // Function used to test ambiguity resolution
   {
       printf("\nI'm in the function.");
       printf("  Incrementing call count to %d.", ++call_count);
       return(-32767);
   }

   void main()
   {
       short S();   // Declaration of function.  LEGAL.

       S();         // No type causes call to S(). LEGAL.

       class S();   // No class S exists.  ILLEGAL.

       if(call_count != 1)
           printf("\n\n*** TEST FAILED ***\n");
       else
           printf("\n\n*** TEST PASSED ***\n");
   }

REFERENCES

The Annotated C++ Reference Manual (ARM), Ellis and Stroustrup, section 9.1.


Additional reference words: 1.00 1.50 7.00 8.00 8.00c
KBCategory: kbtool kbbuglist
KBSubcategory: CPPIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.