[libcxx] r293926 - Avoid implementation defined behavior in a test.

Dan Albert via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 2 11:44:11 PST 2017


Author: danalbert
Date: Thu Feb  2 13:44:11 2017
New Revision: 293926

URL: http://llvm.org/viewvc/llvm-project?rev=293926&view=rev
Log:
Avoid implementation defined behavior in a test.

Summary:
num_put::put uses %p for pointer types, but the exact format of %p is
implementation defined behavior for the C library. Compare output to
snprintf for portability.

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF

Subscribers: cfe-commits

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

Modified:
    libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp

Modified: libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp?rev=293926&r1=293925&r2=293926&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp Thu Feb  2 13:44:11 2017
@@ -38,6 +38,12 @@ int main()
         char str[50];
         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
         std::string ex(str, iter.base());
-        assert(ex == "0x0" || ex == "(nil)");
+        char expected_str[32] = {};
+        // num_put::put uses %p for pointer types, but the exact format of %p is
+        // implementation defined behavior for the C library. Compare output to
+        // snprintf for portability.
+        int rc = snprintf(expected_str, sizeof(expected_str), "%p", v);
+        assert(rc > 0);
+        assert(ex == expected_str);
     }
 }




More information about the cfe-commits mailing list