https://github.com/UebelAndre created 
https://github.com/llvm/llvm-project/pull/228405

`CXUnsavedFile::Length` is `unsigned long`, which is 32 bits on 64-bit Windows. 
Initializing it from `std::string::size()` inside the braced initializer is a 
narrowing conversion there: MSVC reports `C4838` and clang-cl 
`-Wc++11-narrowing`, both fatal under `/WX`. Cast explicitly.

>From 1ce8672ec681cecb6f4687ef1d682d2058a7fad2 Mon Sep 17 00:00:00 2001
From: UebelAndre <[email protected]>
Date: Fri, 2 Oct 2026 05:06:50 -0700
Subject: [PATCH] [libclang][test] Avoid narrowing when initializing
 CXUnsavedFile::Length

`CXUnsavedFile::Length` is `unsigned long`, which is 32 bits on 64-bit
Windows. Initializing it from `std::string::size()` inside the braced
initializer is a narrowing conversion there: MSVC reports `C4838` and
clang-cl `-Wc++11-narrowing`, both fatal under `/WX`. Cast explicitly.
---
 clang/unittests/libclang/TestUtils.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang/unittests/libclang/TestUtils.h 
b/clang/unittests/libclang/TestUtils.h
index 013aad17358211f..27543d0a63d28b9 100644
--- a/clang/unittests/libclang/TestUtils.h
+++ b/clang/unittests/libclang/TestUtils.h
@@ -82,9 +82,11 @@ class LibclangParseTest : public ::testing::Test {
         fixed_addr_string(new std::string(Filename)),
         fixed_addr_string(new std::string(Contents))));
     UnsavedFiles.push_back({
-        it.first->first->c_str(),   // filename
-        it.first->second->c_str(),  // contents
-        it.first->second->size()    // length
+        it.first->first->c_str(),  // filename
+        it.first->second->c_str(), // contents
+        // CXUnsavedFile::Length is `unsigned long`, which is 32 bits on
+        // 64-bit Windows, so converting from size_t here narrows.
+        static_cast<unsigned long>(it.first->second->size()) // length
     });
   }
   template <typename F>

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to