nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.25k stars 6.57k forks source link

Change member variable from 'is' to 'is_' to avoid possible (macro) name collision #4406

Open LiAuTraver opened 6 days ago

LiAuTraver commented 6 days ago

TL; DR: This pull request was attempting to addresses potential naming collisions with macros defined by users of the library. Specifically, the member variable is in the input_adapter class has been renamed to is_ and sb to sb_.


Description

I was working on a project for my professor when we encountered issues caused by some users who came from Java/C# and defined is as a macro in their code. This macro interfered with the library internal implementation, resulting in unexpected behavior and compilation errors due to the macro replacing variables named is in the library's internal implementation.

I admit defining is is very inappropriate and was a bad idea and inadvisable for them. It's the user's fault to do that and definitely out of control of this json library, however, I believe that issues caused by such keyword-like named variables are avoidable. To prevent potential naming collisions and improve compatibility with user-defined macros, in the input_adapter class, I

This is similar to the practice in the C++ standard library, which avoids using common words as variable names and instead uses names with underscores to minimize naming collisions. Although I don't believe changes were necessary in unit_regression.cpp in tests folder, I applied the same renaming for consistency.


As a freshman at university, I'm not sure whether this is actually an issue yet. If it isn't as important as I thought, sorry for bothering!

Pull request checklist