Browse Source

Trade: and you, MSVC 2015, need a special place in hell.

pull/459/head
Vladimír Vondruš 6 years ago
parent
commit
baa23ffd10
  1. 12
      src/Magnum/Trade/MaterialData.h
  2. 9
      src/Magnum/Trade/Test/MaterialDataTest.cpp

12
src/Magnum/Trade/MaterialData.h

@ -2636,7 +2636,17 @@ template<class T
#ifndef DOXYGEN_GENERATING_OUTPUT
, class
#endif
> constexpr MaterialAttributeData::MaterialAttributeData(const Containers::StringView name, const T& value) noexcept: _data{Implementation::MaterialAttributeTypeFor<T>::type(), (CORRADE_CONSTEXPR_ASSERT(name.size() + sizeof(T) + 2 <= Implementation::MaterialAttributeDataSize, "Trade::MaterialAttributeData: name" << name << "too long, expected at most" << Implementation::MaterialAttributeDataSize - sizeof(T) - 2 << "bytes for" << Implementation::MaterialAttributeTypeFor<T>::type() << "but got" << name.size()), name), value} {}
> constexpr MaterialAttributeData::MaterialAttributeData(const Containers::StringView name, const T& value) noexcept:
_data{Implementation::MaterialAttributeTypeFor<T>::type(),
/* MSVC 2015 complains about "error C2065: 'T': undeclared identifier"
in the lambda inside this macro. Sorry, the assert will be less
useful on that stupid thing. */
#ifndef CORRADE_MSVC2015_COMPATIBILITY
(CORRADE_CONSTEXPR_ASSERT(name.size() + sizeof(T) + 2 <= Implementation::MaterialAttributeDataSize, "Trade::MaterialAttributeData: name" << name << "too long, expected at most" << Implementation::MaterialAttributeDataSize - sizeof(T) - 2 << "bytes for" << Implementation::MaterialAttributeTypeFor<T>::type() << "but got" << name.size()), name)
#else
(CORRADE_CONSTEXPR_ASSERT(name.size() + sizeof(T) + 2 <= Implementation::MaterialAttributeDataSize, "Trade::MaterialAttributeData: name" << name << "too long, got" << name.size() << "bytes"), name)
#endif
, value} {}
/* The 4 extra bytes are for a null byte after both the name and value, a type
and a string size */

9
src/Magnum/Trade/Test/MaterialDataTest.cpp

@ -821,11 +821,18 @@ void MaterialDataTest::constructAttributeTooLarge() {
Error redirectError{&out};
MaterialAttributeData{"attributeIsLong", Matrix3x4{}};
/* Constexpr variant has the same assert, but in the header. It should have
the same output. */
the same output. Except on MSVC 2015, which is a crap thing and gets
lost when encountering T in there, so the assert is less useful. */
/*constexpr*/ MaterialAttributeData{"attributeIsLong"_s, Matrix3x4{}};
#ifndef CORRADE_MSVC2015_COMPATIBILITY
CORRADE_COMPARE(out.str(),
"Trade::MaterialAttributeData: name attributeIsLong too long, expected at most 14 bytes for Trade::MaterialAttributeType::Matrix3x4 but got 15\n"
"Trade::MaterialAttributeData: name attributeIsLong too long, expected at most 14 bytes for Trade::MaterialAttributeType::Matrix3x4 but got 15\n");
#else
CORRADE_COMPARE(out.str(),
"Trade::MaterialAttributeData: name attributeIsLong too long, expected at most 14 bytes for Trade::MaterialAttributeType::Matrix3x4 but got 15\n"
"Trade::MaterialAttributeData: name attributeIsLong too long, got 15 bytes\n");
#endif
}
void MaterialDataTest::constructAttributeTooLargeString() {

Loading…
Cancel
Save