Hello all,

(Re-adding gcc-patches, since it got dropped and missed six emails)

=== CPP FEATURE SUGGESTION ===

Adding line directives inside of a macro expansion to differentiate between 
system tokens and user tokens is a valid solution. As Manuel pointed out, there 
would need to be many line directives.

So, if "#define FOO(x) (x) + 1/0" was in a system file, and was instantiated 
from a user file like "FOO(2/0)", the "2/0" are user tokens (which should raise 
a div-by-zero warning), but the "1/0" are system tokens (and so should not 
raise a warning). This would need to expand as follows:

# 1 "user.cpp" 3
(
# 1 "user.cpp" 
2/0
# 1 "user.cpp" 3
) + 1/0
# 2 "user.cpp"

The last line directive is crucial, to specify that the rest of the file is not 
comprised of user tokens.

Currently, compiling a user program with "FOO(2/0)" yields a single div-by-zero 
error. Compiling that same program with -no-integrated-cpp yields two errors: 
the original and correct 2/0 error, but also the 1/0 system error. So adjusting 
the preprocessor to emit extra line directives would be consistent with the 
integrated-cpp mode.


=== NEXT STEPS ===

The bugzilla report now has two independent reports, so this is an issue which 
is currently affecting the community. Both reports, it should be noted, stem 
from the use of ccache, which caches preprocessed output (since this bug is not 
present with integrated preprocessing).

The status quo is subtle and infrequent, but confounding. The extremely 
specific requirements to trigger the bug mean that it is effectively 
undiagnosable (my initial bug report was the result of a very chance set of 
circumstances and a lot of elbow grease, which ended up being the reason for a 
years-old abnormality in our error messages). Further, when the bug does 
happen, it is severely detrimental, since it disables warnings in the rest of 
the file. Given these two circumstances, undiagnosability and high-impact, I 
think that a fix should be applied immediately.

We currently have two possible approaches. I see the trade-offs between these 
two solutions as follows:

Adding full line directives is not implemented, and will be more complicated 
than my patch. It will require someone else to implement it, but should fix the 
problem in its entirety.

My solution is simple, battle-tested (I've had it in our production gcc for a 
few months now), and ready to roll. The primary downside is that it will not 
supress system-token errors in macro expansions (though in my experience this 
is not a problem).



Cheers,
Nicholas

Reply via email to