[clang] [clang][diagnostics] Update note_constexpr_invalid_cast to use enum_select and adjust its uses (PR #130868)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 24 08:52:26 PDT 2025
erichkeane wrote:
> Hey @erichkeane, I'm back! So I'd thought to generalize a bit with the replacements. I saw one with magic numbers in the switch statement just before the diag call and tried to use an enum select there as well. The variable DiagSelect is one-indexed so the default value in the switch steatment is zero. If I change it to use enum_select (which is zero indexed) I would have to change the default value to -1 instead. My question is that why is DiagSelect one-indexed if it's just gonna be subreacted by 1 later on? Is it just legacy to have defaults as 0? And if so, this case should not be up for replacement?
> <img alt="Screenshot 2025-06-17 at 12 02 07 PM" width="688" src="https://private-user-images.githubusercontent.com/121697771/456144551-155e1065-1aed-40a2-940c-73600211aaa7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTA3ODA0MjIsIm5iZiI6MTc1MDc4MDEyMiwicGF0aCI6Ii8xMjE2OTc3NzEvNDU2MTQ0NTUxLTE1NWUxMDY1LTFhZWQtNDBhMi05NDBjLTczNjAwMjExYWFhNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwNjI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDYyNFQxNTQ4NDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hZTZiNmE1ZTc3MjdhYmU0NmE3ZjYzZDE5ZWY3NWZiOTY1ZWI4MTA1OWY5NTFmMTE1Y2QwNTg2Nzk4YzQ0ZmI4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.lh7oHc8st6ZTAxYxTqGAX-kk8MccP53_d_tetvETzRY">
Oh boy! That is an interesting function. DiagSelect there is being used as 1-index because they wanted to use '0' as the 'don't diag' mechanism. It seems to me that making it a `std::optional` might be a more clear way of doing this, and would make it a good candidate for enum_select.
https://github.com/llvm/llvm-project/pull/130868
More information about the cfe-commits
mailing list