From bc32ffeaae78373e5fe057a82e6d00edc2672737 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Tue, 1 Nov 2016 11:24:18 -0700 Subject: [PATCH] Eliminate more VLAs Summary: MSVC doesn't support them, so use dynamic allocation instead. This also fixes a place where MSVC wasn't propogating the constexpr-ness of a local into the body of a lambda, resulting in an attempt to create a VLA. Reviewed By: yfeldblum Differential Revision: D4098932 fbshipit-source-id: 742b2fcd96f7f6eceb5043159403d557f7fc9673 --- folly/fibers/test/FibersTest.cpp | 2 +- folly/test/StringTest.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/folly/fibers/test/FibersTest.cpp b/folly/fibers/test/FibersTest.cpp index 859ccda3..d11ddb30 100644 --- a/folly/fibers/test/FibersTest.cpp +++ b/folly/fibers/test/FibersTest.cpp @@ -2057,7 +2057,7 @@ TEST(FiberManager, recordStack) { auto& loopController = dynamic_cast(fm.loopController()); - constexpr size_t n = 1000; + static constexpr size_t n = 1000; int s = 0; fm.addTask([&]() { int b[n] = {0}; diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index e1fd686b..415c6c3d 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -1103,11 +1103,12 @@ char* copyWithSameAlignment(char* dst, const char* src, size_t length) { void testToLowerAscii(Range src) { // Allocate extra space so we can make copies that start at the // same alignment (byte, word, quadword, etc) as the source buffer. - char controlBuf[src.size() + 7]; - char* control = copyWithSameAlignment(controlBuf, src.begin(), src.size()); + auto controlBuf = std::vector(src.size() + 7); + char* control = + copyWithSameAlignment(controlBuf.data(), src.begin(), src.size()); - char testBuf[src.size() + 7]; - char* test = copyWithSameAlignment(testBuf, src.begin(), src.size()); + auto testBuf = std::vector(src.size() + 7); + char* test = copyWithSameAlignment(testBuf.data(), src.begin(), src.size()); for (size_t i = 0; i < src.size(); i++) { control[i] = tolower(control[i]); -- 2.34.1