Microsoft KB Archive/136594

= FIX: Error Using Inline Assembly in a Template Class =

Article ID: 136594

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1
 * Microsoft Visual C++ 6.01 Professional Edition

-



This article was previously published under Q136594



SYMPTOMS
If inline assembly is used in an inline member function defined within a templated class, the compiler generates these errors:

If the assembly instruction is of the form _asm { int 3 }:

      error C2304: ' }' : unexpected tokens following type fatal error C1004: unexpected end of file found.

If the assembly instruction is of the form _asm int 3:

      fatal error C1075: end of file found before the left  at was matched.

The type of error depends on whether the assembly instruction is enclosed in braces or not.

NOTE: The same error occurs for macros like ASSERT and VERIFY, which expand to an _asm {int 3} instruction.



RESOLUTION
Define the member function outside the templated class using the "inline" keyword.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Microsoft Visual C++, 32-bit Edition, version 4.0.



Sample Code to Reproduce Problem
/* Compile options needed: /Ob1 or /Ob2 for the workaround function /*                                     to be inline

template class myclass { public: void good_fun; void bad_fun { _asm {int 3}     // This generates a compiler error. } };

template inline void myclass ::good_fun { _asm {int 3}     // This doesn't generate an error. }

void main(void) { myclass mytest; } In this code, the good_fun compiles without any error.

Additional query words: 2.00 2.10 2.20 9.00 9.10

Keywords: kbbug kbfix kbcpponly kbcompiler KB136594

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.