[libcxx-commits] [libcxx] 1b4c0cb - [libc++] Avoid potential truncation warnings in std::abs test

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 19 11:22:30 PST 2021


Author: Louis Dionne
Date: 2021-11-19T14:22:26-05:00
New Revision: 1b4c0cb3918a9f2d12f8259407fc8bce053e78bf

URL: https://github.com/llvm/llvm-project/commit/1b4c0cb3918a9f2d12f8259407fc8bce053e78bf
DIFF: https://github.com/llvm/llvm-project/commit/1b4c0cb3918a9f2d12f8259407fc8bce053e78bf.diff

LOG: [libc++] Avoid potential truncation warnings in std::abs test

One some platforms, -Wimplicit-int-conversion is enabled by default,
which can lead to additional warnings being triggered in this test.
Since we're only trying to test errors related to calling abs(), the
assignment is superfluous.

As a fly-by fix, correct one instance of ::abs to std::abs and made
the test a .verify.cpp test instead.

Differential Revision: https://reviews.llvm.org/D114244

Added: 
    libcxx/test/std/numerics/c.math/abs.verify.cpp

Modified: 
    

Removed: 
    libcxx/test/std/numerics/c.math/abs.fail.cpp


################################################################################
diff  --git a/libcxx/test/std/numerics/c.math/abs.fail.cpp b/libcxx/test/std/numerics/c.math/abs.verify.cpp
similarity index 50%
rename from libcxx/test/std/numerics/c.math/abs.fail.cpp
rename to libcxx/test/std/numerics/c.math/abs.verify.cpp
index d58cf0d563d18..dec80762b214f 100644
--- a/libcxx/test/std/numerics/c.math/abs.fail.cpp
+++ b/libcxx/test/std/numerics/c.math/abs.verify.cpp
@@ -8,24 +8,19 @@
 
 #include <cmath>
 
-#include "test_macros.h"
-
-int main(int, char**)
-{
+void f() {
     unsigned int ui = -5;
-    ui = std::abs(ui); // expected-error {{call to 'abs' is ambiguous}}
+    (void)std::abs(ui); // expected-error {{call to 'abs' is ambiguous}}
 
     unsigned char uc = -5;
-    uc = std::abs(uc); // expected-warning {{taking the absolute value of unsigned type 'unsigned char' has no effect}}
+    (void)std::abs(uc); // expected-warning {{taking the absolute value of unsigned type 'unsigned char' has no effect}}
 
     unsigned short us = -5;
-    us = std::abs(us); // expected-warning {{taking the absolute value of unsigned type 'unsigned short' has no effect}}
+    (void)std::abs(us); // expected-warning {{taking the absolute value of unsigned type 'unsigned short' has no effect}}
 
     unsigned long ul = -5;
-    ul = std::abs(ul); // expected-error {{call to 'abs' is ambiguous}}
+    (void)std::abs(ul); // expected-error {{call to 'abs' is ambiguous}}
 
     unsigned long long ull = -5;
-    ull = ::abs(ull); // expected-error {{call to 'abs' is ambiguous}}
-
-    return 0;
+    (void)std::abs(ull); // expected-error {{call to 'abs' is ambiguous}}
 }


        


More information about the libcxx-commits mailing list