Opened 13 years ago

Closed 13 years ago

#1686 closed defect (fixed)

"auto" keyword changes syntax meaning in VS2010

Reported by: ChristineBao Owned by:
Priority: high Milestone:
Component: General Version: 2.1.0
Severity: blocker Keywords:
Cc: External ID:

Description

"auto" keyword changes syntax meaning in VS2010. http://msdn.microsoft.com/en-us/library/6k3ybftz.aspx

The auto keyword is a declaration specifier. However, the C++ standard defines an original and a revised meaning for this keyword. Before Visual C++ 2010, the auto keyword declares a variable in the automatic storage class; that is, a variable that has a local lifetime. Starting with Visual C++ 2010, the auto keyword declares a variable whose type is deduced from the initialization expression in its declaration. 

This change caused project $OS\Oem\DWFTK7.1\develop\global\build\VC 8.0\W3DToolkit\W3DToolkit.vcxproj build fails because there are numerous of "auto" keyword used in such way as:

    auto        TK_Status       status = TK_Normal;

In the new syntax meaning of VS2010, it should used either without "auto"

    TK_Status       status = TK_Normal;


or without the varable type.

    auto        status = TK_Normal;

A compiler option "/Zc:auto-" is supposed to make VS2010 recognize "auto" in the old way, however it works for debug|win32 and release|win32, but fails for debug|x64 and release|x64. In x64 it always says:
cl : Command line warning D9025: overriding '/Zc:auto-' with '/Zc:auto'[[BR]] And then build fail.
A testing project is attached.

Attachments (1)

Auto_Keyword.zip (5.2 KB ) - added by ChristineBao 13 years ago.

Download all attachments as: .zip

Change History (3)

by ChristineBao, 13 years ago

Attachment: Auto_Keyword.zip added

comment:1 by ChristineBao, 13 years ago

There are two approaches to solve this problem:

  1. Remove "auto" keyword.

"auto" keyword does not have special meaning in old C++, that is:

    auto        TK_Status       status = TK_Normal;


is the same meaning as

    TK_Status       status = TK_Normal;


So the fixing is to remove "auto" keyword in $OS\Oem\DWFTK7.1\develop\global\build\VC 8.0\W3DToolkit\W3DToolkit.vcxproj code files, including both header file and code file.
I will hold till tomorrow May 11th to start this removing, so if you have any suggestion, please reply to me as soon as possible'''

  1. Remove "auto" keyword in VS2010 build only

If there is reason to keep "auto" keyword, the fixing is to isolate non-VS2010 and VS2010 in such as way:

//http://msdn.microsoft.com/en-us/library/b0084kay%28VS.80%29.aspx. Define for VS2010
#if _MSC_VER >= 1600
    TK_Status       status = TK_Normal;
#elseif
    auto        TK_Status       status = TK_Normal;
#endif

comment:2 by ChristineBao, 13 years ago

Resolution: fixed
Status: newclosed

Fix this defect by using "/Zc:auto-" in "Project properties --> C/C++ --> Command Line".
If some machine show "cl : Command line warning D9025: overriding '/Zc:auto-' with '/Zc:auto'", uncheck the "inherit from parent or project defaults".

Note: See TracTickets for help on using tickets.