ayushpareek2003 wrote:

> Could you elaborate? Why `= {}` is better than `.clear()` ?

according to my understanding, Clang stores some build-specific data in 
CodeGenOptions like file paths and debug info. When generating modules or 
precompiled headers, this data can make the output different from build to 
build. To avoid that, we reset those fields.

I changed .clear() to = {} because, as I understand, = {} resets the entire 
field to its default value, not just empties it. This is helpful because it 
works safely across different types—not just std::string, but also for types 
like std::optional, smallString, or other structs that might be used in the 
future. Using = {} makes it easier to refactor or extend the structure later 
without having to update every .clear() call. It also communicates intent more 
clearly: we’re not just clearing content, we’re fully resetting the field. This 
reduces the risk of leaking build-specific paths or flags into the output, and 
helps make Clang’s module and PCH output more consistent and reproducible 
across different systems. I did this to make the code more future-proof, 
maintainable, and reliable.





https://github.com/llvm/llvm-project/pull/138256
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to