After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 339794 - comments syntax-highlighting problem with c-code
comments syntax-highlighting problem with c-code
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: Syntax files
1.6.x
Other Linux
: Normal minor
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2006-04-26 10:47 UTC by Sebastien Bacher
Modified: 2007-08-20 12:16 UTC
See Also:
GNOME target: ---
GNOME version: 2.13/2.14



Description Sebastien Bacher 2006-04-26 10:47:55 UTC
That bug has been described on https://launchpad.net/distros/ubuntu/+source/gedit/+bug/41345

"following c-code will be highlighted wrong:
   if(key == 0xdf) key = 0x5c; //sz -> \\
   if(key == '+') key = '~';

the second line is also a comment due the backslash at the end, but is not highlighted as such. because i assume gedit thinks the backslash has been escaped, but gcc does not care and assumes the next line to be a comment as well.
for example vim handles this correctly."
Comment 1 Steve Frécinaux 2006-04-26 11:36:17 UTC
This small code snippet can reproduce the bug :

#include <stdio.h>

int
main (int argv, char *argc)
{
	char *test;

	test = "foo\n"; // \\
	test = "bar\n";
	
	printf(test);
}

[sf:antea] tmp $ gcc test-bug.c
[sf:antea] tmp $ ./a.out
foo

Anyway, it should be tested with other compilers than gcc before confirming, since it could as well be a gcc bug. (this is a corner case and it seems weird to me that the C standard envisages such a behaviour)
Comment 2 Michel Boto 2007-02-15 16:11:48 UTC
This is not a bug, it is a consequence of a GCC convenience add-on. //-style comments are part of C++, not ANSI C. GCC supports using them, however, and thus compiles the testcases. Adding -pedantic -ansi compiler flags to enforce the standard will cause this testcode to fail. Additionally, an escaping backslash is not supposed to have anything follow it except a newline.

Just change

test = "foo\n"; // \\
test = "bar\n";

to

test = "foo\n"; // \
test = "bar\n";

to highlight it the way GCC is seeing it. If you want proof that escaping backslashes aren't supposed to have anything follow them, try to compile this:

#define FOOBARBAZ  "foo" \ /* this comment will error */
        "bar" \
        "baz"

int main()
{
        printf(FOOBARBAZ);
        return 0;
}

Remove the /* */ comment and try it again. Works all of a sudden, eh? Add some whitespace after one of the escaped slashes and see if it gives you a warning like, "warning: backslash and newline separated by space."
Comment 3 Steve Frécinaux 2007-02-15 17:16:44 UTC
> //-style comments are part of C++, not ANSI C.

Actually it is part of C now. Ever heard of C99 ?
Comment 4 Paolo Borelli 2007-08-20 12:16:46 UTC
fixed in the new highlighing engine