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

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 7 23:25:03 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())
----------------
MaskRay wrote:

I created https://github.com/llvm/llvm-project/pull/77278 to simplify the code.

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


More information about the cfe-commits mailing list