[clang] [Tooling/Inclusion] Avoid narrowing-conversions in macro expansion (PR #72664)
Krzysztof Parzyszek via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 17 07:25:49 PST 2023
https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/72664
```
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:144:65: warning: narrowing conversion of ‘llvm::StringRef(((const char*)"std::experimental::filesystem::")).llvm::StringRef::size()’ from ‘size_t’ {aka ‘long un signed int’} to ‘unsigned int’ [-Wnarrowing]
144 | #define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size(), #Header},
| ~~~~~~~~~~~~~~~~~~~^~
clang/lib/Tooling/Inclusions/Stdlib/StdTsSymbolMap.inc:51:1: note: in expansion of macro ‘SYMBOL’
51 | SYMBOL(temp_directory_path, std::experimental::filesystem::, <experimental/filesystem>)
| ^~~~~~
```
>From c720fc96d8b92e5eccdd594c2b3d6bbc71d81455 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Fri, 17 Nov 2023 09:18:02 -0600
Subject: [PATCH] [Tooling/Inclusion] Avoid narrowing-conversions in macro
expansion
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:144:65: warning:
narrowing conversion of ‘llvm::StringRef(((const char*)"std::experiment
al::filesystem::")).llvm::StringRef::size()’ from ‘size_t’ {aka ‘long un
signed int’} to ‘unsigned int’ [-Wnarrowing]
144 | #define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size
(), #Header},
| ~~~~~~~~~~~~~~~~~~~
^~
clang/lib/Tooling/Inclusions/Stdlib/StdTsSymbolMap.inc:51:1: note: in ex
pansion of macro ‘SYMBOL’
51 | SYMBOL(temp_directory_path, std::experimental::filesystem::, <ex
perimental/filesystem>)
| ^~~~~~
---
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 03f61d33e1f26e7..adf1b230ff03181 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -141,7 +141,9 @@ static int initialize(Lang Language) {
unsigned NSLen;
const char *HeaderName;
};
-#define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size(), #Header},
+#define SYMBOL(Name, NS, Header) \
+ {#NS #Name, static_cast<decltype(Symbol::NSLen)>(StringRef(#NS).size()), \
+ #Header},
switch (Language) {
case Lang::C: {
static constexpr Symbol CSymbols[] = {
More information about the cfe-commits
mailing list