Closed
Description
Normally, 3c
prints the rewritten version of a file foo.c
to standard output, or if -output-postfix=checked
is passed, the rewritten version is written to foo.checked.c
. However, if the rewritten version is identical to the original, then:
- Without
-output-postfix
, the output to standard output is empty. This edge case is bound to cause scripts to behave unexpectedly if they think the result of rewriting is actually an empty file. John pointed out that many of the regression tests take advantage of this behavior to assert that a file needs no rewriting by checking that the output is empty (look forcount 0
), but we think the tests could just as easily (and more clearly!)cmp
to the original file. - With
-output-postfix
, thefoo.checked.c
file is not created. Hopefully scripts not designed for this case will just error out instead of doing something wrong. Some users might consider this useful and there might be a performance benefit in some workflows, but there is at least one other reason why a given file might not be written (-base-dir
), soif we keep the behavior, we should tell the user why a given file wasn't written.Update 2021-02-13: We've deprioritized that part because it's now an error if 3C generates a change to a file outside the base dir (Properly constrain non-canWrite
files to not change (remaining cases) #387), so we're not aware of any other common reason for not writing a file that would need to be distinguished from the file being unchanged; if one arises, we'll try to make sure that that one generates a distinctive message. And the code that writes the files only has a list of modified rewrite buffers; I'm not aware of an easy way to get a list of files that were read but not modified.
This issue is to decide whether to stop treating unchanged files specially in one or both cases (or maybe make it an option), and if we keep the special treatment with -output-postfix
, provide better diagnostics.
Note that even if we write unchanged files passed on the command line (by default or as an option), we might not want to write unchanged files included from the -base-dir
, at least without an additional option.