Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336193

Summary: C++ semantic error highlighting (e.g. undeclared variable) doesnt work in CDT
Product: [Tools] CDT Reporter: Sam <sam_woods83>
Component: cdt-parserAssignee: Project Inbox <cdt-parser-inbox>
Status: RESOLVED WORKSFORME QA Contact: Markus Schorn <mschorn.eclipse>
Severity: major    
Priority: P3 CC: cdtdoug
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Sam CLA 2011-02-03 02:35:43 EST
Build Identifier: 20100917-0705

I downloaded and installed the latest version of Eclipse CDT yesterday. Everything is on the default setting, I havent changed anything.

Now, when I enter an assignment statement (for example), without declaring the variable I'm using it does NOT flag an error. Eg:
main ()
{
 foo = 1 ;
}
So the above line does not get a red underline, even though foo is an undeclared identifier.

Now, if I run the program with Ctrl+F11, the build fails and a red underline finally appears in the editor under the statement foo = 1 ;

But if I now declare the variable foo above the assignment, the red underline still remains visible. Only after I hit Ctrl+F11, does the red line disappear.

The same thing happens with the following code snippet:
int a ;
string * s ;
s = &a ;

Here the last assignment s = &a should be flagged as an error in C++ (because the cast is illegal). However the editor does not flag this error till the code is actually built. And then again, once the editor displays the red underline, it does not disappear even if the assignment is rectified. The underline disappears only after the project is built.


Other observations:

The editor does not flag the error if I merely save the file after entering the erroneous statement.

If I enter a statement with a syntax error, such as "foo = " (without the quotes), the editor flags the error immediately as I type with an orange underline.

Reproducible: Always

Steps to Reproduce:
1.Enter the statement "foo = 1 ;" in the editor without the quotes in main ().
2.BUG: Notice that the editor does not flag the statement as an error.
3.Now build the project.
4.The build fails (as shown on console) because foo is undeclared.
5.Observe that the editor now flags the statement as an error by underlining it in red.
6.Declare the variable above its usage: "int foo ;"
7.BUG: Observe that the editor does not remove the red underline from the statment "foo = 1 ;"
8.Build the project again.
9.Observe that the red underline is now gone.
Comment 1 Andrew Gvozdev CLA 2011-02-03 09:52:15 EST
It works fine in upcoming version CDT 8.0. Try the latest build from http://download.eclipse.org/tools/cdt/builds/8.0.0/index.html:

I got in my sample project following:
Symbol 'foo' could not be resolved	SampleProject.cpp	/SampleProject	line 14	Semantic Error
Comment 2 Sam CLA 2011-02-04 02:31:27 EST
(In reply to comment #1)
> It works fine in upcoming version CDT 8.0. Try the latest build from
> http://download.eclipse.org/tools/cdt/builds/8.0.0/index.html:
> 
> I got in my sample project following:
> Symbol 'foo' could not be resolved    SampleProject.cpp    /SampleProject   
> line 14    Semantic Error

When I try installing version 8.0 latest build, it stops recognizing my cygwin toolchain. This is the build I tried: http://download.eclipse.org/tools/cdt/builds/8.0.0/I.I201101311025/index.html

I followed the instructions as stated on this page for installation.

Thanks.
Comment 3 Andrew Gvozdev CLA 2011-02-04 07:17:58 EST
If you have problem with cygwin, please open another bug and provide details. This problem is different from stated in description.