VS 2010 RC intellisense C++ incorrectly reports undefined identifier - by jmatthewsr

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 534892 Comments
Status Closed Workarounds
Type Bug Repros 6
Opened 2/19/2010 9:37:15 AM
Access Restriction Public


If a sub-folder is created within a project and a .cpp files references a define in an stdafx.h file that is in the parent directory, intellisense reports that the identifier is undefined and places the red squiggly underneath the identifier.  The project settings specify "additional included directories" as "../" so the solution and project compile without issues.
Sign in to post a comment.
Posted by Microsoft on 3/24/2010 at 1:59 PM
Hello jmatthewsr,

This behavior is by design. This is very similar to the following connect bug.


The problem here is that "TestSubDir1.cpp" is in a different directory than the stdafx.h (with the #define STR_HELLO). Since "TestSubDir1.cpp" is using PCH, the compiler (cl.exe) was able to find the definition of STR_HELLO inside the PCH file instead of the actual header. The intellisense parser, however, uses a different PCH mechanism compared to cl.exe. The intellisense parser uses the include path to find the header, stdafx.h. I think you had the right idea by trying to use the "additional include directories" to help the intellisense parser to find the missing stdafx.h However, since the intellisense parser (and the normal compiler, cl.exe, as well) is invoked at the project directory (ie. testinelli\subproject1), by adding "..\", the intellisense parser picked up testintelli\stdafx.h instead of testintelli\subproject1\stdafx.h. You can confirm this by building "subproject1" with PCH disabled. The normal compiler, cl.exe, will give the same undeclared identifier error.

The correct fix to add ".\" or "$(ProjectDir)" to the "subproject1" project. In this case, "$(ProjectDir)" will expand to testintelli\subproject1.

jkolb1, davidjward30, can you try adding "$(ProjectDir)" to the "additional include directories" to see if that fixes your problem or not? If not, you can open another Connect bug or email directly at alanch 'at' microsoft.com.

Alan Chan
Visual C++ Dev
Posted by davidjward30 on 3/24/2010 at 10:04 AM
I have a very simply repro. Just create a blank Win32 console application with a pch. Create a subfolder with a .cpp that does

#include "stdafx.h"

Intellisense can't find "stdafx.h", even though the code compiles fine. Interestingly all the "open document", "go to header file" menu options locate the file correctly.

Happy to send the repro if necessary.
Posted by Microsoft on 2/22/2010 at 2:48 AM
Thanks for your feedback.

We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/19/2010 at 7:04 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by jkolb on 2/19/2010 at 10:17 AM
I see this too but I couldn't figure out a good repro case. It's marking all of my stl containers as invalid identifiers because I include them in the precompiled header.