[clang-tools-extra] [clang-tidy] Add portability-avoid-platform-specific-fundamental-types (PR #146970)
JJ Marr via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 6 13:41:49 PDT 2025
================
@@ -0,0 +1,100 @@
+// RUN: %check_clang_tidy %s portability-avoid-platform-specific-fundamental-types %t -- -config="{CheckOptions: [{key: portability-avoid-platform-specific-fundamental-types.WarnOnFloats, value: true}]}" -header-filter=.* -- -std=c++23
+
+// Mock fixed-width float types
+// In reality, these types are aliases to "extended floating point types", and
+// are not typedefs. However, there isn't a good way to mock extended floats as
+// they are not fundamental types.
+// NOLINTBEGIN(portability-avoid-platform-specific-fundamental-types)
+typedef float float32_t;
+typedef double float64_t;
+// NOLINTEND(portability-avoid-platform-specific-fundamental-types)
+
+// Test floating point types that should trigger warnings when WarnOnFloats is enabled
+float global_float = 3.14f;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: avoid using platform-dependent floating point type 'float'; consider using 'float32_t' instead [portability-avoid-platform-specific-fundamental-types]
+// CHECK-FIXES: float32_t global_float = 3.14f;
----------------
jj-marr wrote:
Not done. I want to make this another check, maybe "`readability-inconsistent-literal-suffix`".
https://github.com/llvm/llvm-project/pull/146970
More information about the cfe-commits
mailing list