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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@293926 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Albert
2017-02-02 19:44:11 +00:00
parent 1773efdab3
commit e520f0b308

View File

@@ -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);
}
}