gecko-dev/mfbt/tests
Chris Peterson a48326552c Bug 1405582 - Span: delete implicit constructors for char* and char16_t*. r=froydnj,hsivonen
Delete Span's implicit constructors for char* and char16_t* pointers to avoid accidental construction in cases where a pointer does not point to a zero-terminated string. Use the MakeStringSpan() function instead.

I deleted both the const and non-const char* and char16_t* constructors, in the name of cross-compiler consistency. If we only delete the const char* and char16_t* constructors, for some reason, MSVC complains that `Span<char> s(charArray)` uses a deleted constructor while clang nor gcc permit it. I don't know if this is a compiler bug in MSVC or clang and gcc.

Also, do not permit MakeSpan() for string literals (const char and char16_t arrays) because the Span length would include the zero terminator, which may surprise callers. Use MakeStringSpan() to create a Span whose length that excludes the string literal's zero terminator or use the MakeSpan() overload that accepts a pointer and length and specify the string literal's full length.

The following Span usages are prevented:

  Span<const char> span("literal"); // error
  Span<char> span(charArray); // error

  Span<const char> span;
  span = "literal"; // error
  span = charArray; // error

  MakeSpan("literal"); // error

The following Span usages are still permitted:

  assert(MakeStringSpan("literal") == 8); // OK: span length is calculated with strlen() and excludes the zero terminator
  MakeStringSpan(charArray); // OK: span length is calculated with strlen() and excludes the zero terminator
  MakeSpan(charArray); // OK: span length is the char array size including any zero terminator

MozReview-Commit-ID: Et71CpjsiyI

--HG--
extra : rebase_source : f6f8bdb28726f0f2368fdfdd039fb1d7dcf2914e
extra : source : 0547d8924ffc7713d6cf32cc06eeeaf00e0d69a3
2017-09-20 00:38:07 -07:00
..
gtest Bug 1405582 - Span: delete implicit constructors for char* and char16_t*. r=froydnj,hsivonen 2017-09-20 00:38:07 -07:00
TestArray.cpp Bug 1309466 - Add Test for the init value by constructor. r=froydnj 2016-10-19 18:12:11 +08:00
TestArrayUtils.cpp
TestAtomics.cpp
TestBinarySearch.cpp
TestBloomFilter.cpp
TestBufferList.cpp Bug 1297981 - Delete BufferList::FlattenBytes and Pickle::FlattenBytes. r=billm 2016-08-25 17:15:38 +08:00
TestCasting.cpp
TestCeilingFloor.cpp
TestCheckedInt.cpp
TestCountPopulation.cpp
TestCountZeroes.cpp
TestDefineEnum.cpp Bug 1371771 - Add a MOZ_DEFINE_ENUM macro and variants to MFBT. r=froydnj 2017-06-30 19:58:11 -04:00
TestDoublyLinkedList.cpp Bug 1396723 - Simplify the trait users of DoublyLinkedList need to define. r=froydnj 2017-09-02 08:09:58 +09:00
TestEndian.cpp
TestEnumSet.cpp
TestEnumTypeTraits.cpp Bug 1297306 - part4:rename IsEnumFittingWithin with EnumTypeFitsWithin and move it to mfbt/EnumTypeTraits.h. r=froydnj 2016-09-07 10:20:16 +08:00
TestEnumeratedArray.cpp Bug 1309466 - Add Test for the init value by constructor. r=froydnj 2016-10-19 18:12:11 +08:00
TestFastBernoulliTrial.cpp
TestFloatingPoint.cpp Bug 1312620 - Add IsPositiveZero function to mfbt and use it to replace MPhi by MNaNToZero iff c is +0.0. r=nbp, r=waldo 2016-10-26 17:47:42 +02:00
TestIntegerPrintfMacros.cpp Bug 1349957 Change reference (in disabled code) to new/correct member r=froydnj 2017-03-23 10:27:25 -05:00
TestIntegerRange.cpp Bug 1315274 - rename mozilla::MakeRange to mozilla::IntegerRange; r=Waldo 2017-01-06 09:22:53 -05:00
TestJSONWriter.cpp
TestLinkedList.cpp Bug 1310547 - Add removeAndGetNext/Previous methods to LinkedList (r=froydnj) 2016-10-30 22:04:01 -07:00
TestMacroArgs.cpp Bug 1369622 - Fix MOZ_FOR_EACH with an empty list. r=froydnj 2017-06-02 14:53:54 +09:00
TestMacroForEach.cpp Bug 1369622 - Fix MOZ_FOR_EACH with an empty list. r=froydnj 2017-06-02 14:53:54 +09:00
TestMathAlgorithms.cpp Bug 1299284 - Remove js::IsPowerOfTwo in favor of mozilla::IsPowerOfTwo. r=sfink 2016-07-21 00:36:38 -07:00
TestMaybe.cpp Bug 1287006 - Use |alignas(T) unsigned char mStorage[sizeof(T)]| instead of AlignedStorage2 inside Maybe. r=froydnj 2017-01-30 15:56:04 -08:00
TestNotNull.cpp Bug 1018486 - Part 8: Various other changes, r=smaug 2016-09-07 10:50:45 -04:00
TestPair.cpp
TestPoisonArea.cpp Bug 1158445 - posix_madvise() should be used instead of madvise on Solaris. r=froydnj, r=jandem 2017-06-09 00:59:32 -07:00
TestRange.cpp Bug 1315352 - enable Range<T> -> Range<const T> conversion; r=Waldo 2016-11-07 19:30:34 -04:00
TestRefPtr.cpp
TestResult.cpp Bug 1325073 - Rename mozilla::MakeGenericErrorResult to mozilla::Err. r=Waldo 2017-03-08 13:33:07 +00:00
TestRollingMean.cpp
TestSHA1.cpp
TestSaturate.cpp
TestScopeExit.cpp
TestSegmentedVector.cpp Bug 1358761 - dummy handling for return values in test, r=bustage 2017-05-05 10:43:37 +03:00
TestSmallPointerArray.cpp Bug 1397056 - Add Contains and a return parameter to Remove for SmallPointerArray. r=froydnj 2017-09-12 14:11:47 -04:00
TestSplayTree.cpp
TestTemplateLib.cpp
TestTuple.cpp
TestTypeTraits.cpp Bug 1318677 part 3 - mozilla::Result: Add a new packing strategy to pack small enumerated values in a single word. r=Waldo 2017-02-07 18:57:43 +00:00
TestTypedEnum.cpp Bug 1315624 - Delete operator&& and operator|| for CastableTypedEnumResult. r=froydnj 2016-11-07 15:00:16 +08:00
TestUniquePtr.cpp
TestVariant.cpp Bug 1338389 - Tests for Variant's detail::Nth and detail::SelectVariantType - r=froydnj 2017-06-06 16:59:00 +12:00
TestVector.cpp Bug 1329019 - Allow specifying capacity to Vector::replaceRawBuffer (r=froydnj) 2017-09-22 10:34:24 -05:00
TestWeakPtr.cpp
TestXorShift128PlusRNG.cpp
moz.build Bug 1386876 - Replace all uses of DISABLE_STL_WRAPPING with a template, remove DISABLE_STL_WRAPPING. r=glandium 2017-09-11 11:33:26 -07:00