[clang] [Sema] Add -Wc++11-narrowing-const-reference (PR #76094)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 3 07:04:42 PST 2024


================
@@ -10410,40 +10410,53 @@ static void DiagnoseNarrowingInInitList(Sema &S,
     // No narrowing occurred.
     return;
 
-  case NK_Type_Narrowing:
+  case NK_Type_Narrowing: {
     // This was a floating-to-integer conversion, which is always considered a
     // narrowing conversion even if the value is a constant and can be
     // represented exactly as an integer.
-    S.Diag(PostInit->getBeginLoc(), NarrowingErrs(S.getLangOpts())
-                                        ? diag::ext_init_list_type_narrowing
-                                        : diag::warn_init_list_type_narrowing)
+    QualType T = EntityType.getNonReferenceType();
+    S.Diag(PostInit->getBeginLoc(),
+           NarrowingErrs(S.getLangOpts())
----------------
erichkeane wrote:

2-level deep ternary is too much here, please extract logic for all of these to a function to help decide between these three (it may have to use some lookup/casting, but the logic is all seemingly identical).

https://github.com/llvm/llvm-project/pull/76094


More information about the cfe-commits mailing list