diff --git a/src/Magnum/Math/Matrix.h b/src/Magnum/Math/Matrix.h index de7012484..7013f9096 100644 --- a/src/Magnum/Math/Matrix.h +++ b/src/Magnum/Math/Matrix.h @@ -65,7 +65,7 @@ template class Matrix: public RectangularMatrix class Matrix: public RectangularMatrix class RectangularMatrix { /* Implementation for RectangularMatrix::RectangularMatrix(ZeroInitT) and RectangularMatrix::RectangularMatrix(NoInitT) */ /* MSVC 2015 can't handle {} here */ - template constexpr explicit RectangularMatrix(Implementation::Sequence, U): _data{Vector((static_cast(sequence), U{}))...} {} + template constexpr explicit RectangularMatrix(Implementation::Sequence, U): _data{Vector((static_cast(sequence), U{typename U::Init{}}))...} {} template constexpr Vector diagonalInternal(Implementation::Sequence) const; diff --git a/src/Magnum/Math/Tags.h b/src/Magnum/Math/Tags.h index 98a77b5ed..f4f40091d 100644 --- a/src/Magnum/Math/Tags.h +++ b/src/Magnum/Math/Tags.h @@ -47,7 +47,13 @@ typedef Corrade::Containers::NoInitT NoInitT; Used to distinguish construction with all elements set to zero. @see @ref ZeroInit */ -struct ZeroInitT {}; +/* Explicit constructor to avoid ambiguous calls when using {} */ +struct ZeroInitT { + #ifndef DOXYGEN_GENERATING_OUTPUT + struct Init{}; + constexpr explicit ZeroInitT(Init) {} + #endif +}; /** @brief Identity initialization tag type @@ -55,7 +61,13 @@ struct ZeroInitT {}; Used to distinguish construction with transformation set to identity. @see @ref IdentityInit */ -struct IdentityInitT {}; +/* Explicit constructor to avoid ambiguous calls when using {} */ +struct IdentityInitT { + #ifndef DOXYGEN_GENERATING_OUTPUT + struct Init{}; + constexpr explicit IdentityInitT(Init) {} + #endif +}; /** @brief No initialization tag @@ -63,6 +75,7 @@ struct IdentityInitT {}; Use for construction with no initialization at all. */ #ifdef DOXYGEN_GENERATING_OUTPUT +/* Explicit constructor to avoid ambiguous calls when using {} */ constexpr NoInitT NoInit{}; #else using Corrade::Containers::NoInit; @@ -73,14 +86,14 @@ using Corrade::Containers::NoInit; Use for construction with all elements set to zero. */ -constexpr ZeroInitT ZeroInit{}; +constexpr ZeroInitT ZeroInit{ZeroInitT::Init{}}; /** @brief Identity initialization tag Use for construction with transformation set to identity. */ -constexpr IdentityInitT IdentityInit{}; +constexpr IdentityInitT IdentityInit{IdentityInitT::Init{}}; }} diff --git a/src/Magnum/Math/Test/CMakeLists.txt b/src/Magnum/Math/Test/CMakeLists.txt index 7bfde5166..51e0f5e31 100644 --- a/src/Magnum/Math/Test/CMakeLists.txt +++ b/src/Magnum/Math/Test/CMakeLists.txt @@ -26,6 +26,7 @@ corrade_add_test(MathBoolVectorTest BoolVectorTest.cpp) corrade_add_test(MathConstantsTest ConstantsTest.cpp) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathTagsTest TagsTest.cpp) corrade_add_test(MathTypeTraitsTest TypeTraitsTest.cpp) corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Magnum/Math/Test/TagsTest.cpp b/src/Magnum/Math/Test/TagsTest.cpp new file mode 100644 index 000000000..0896f8cf7 --- /dev/null +++ b/src/Magnum/Math/Test/TagsTest.cpp @@ -0,0 +1,49 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Magnum/Math/Tags.h" +#include "Corrade/TestSuite/Tester.h" + +namespace Magnum { namespace Math { namespace Test { + +struct TagsTest: Corrade::TestSuite::Tester { + explicit TagsTest(); + + void noDefaultConstructor(); +}; + +TagsTest::TagsTest() { + addTests({&TagsTest::noDefaultConstructor}); +} + +void TagsTest::noDefaultConstructor() { + CORRADE_VERIFY(!std::is_default_constructible::value); + CORRADE_VERIFY(!std::is_default_constructible::value); + CORRADE_VERIFY(!std::is_default_constructible::value); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::TagsTest) diff --git a/src/Magnum/Tags.h b/src/Magnum/Tags.h index 1cab60360..5f38d72b0 100644 --- a/src/Magnum/Tags.h +++ b/src/Magnum/Tags.h @@ -37,14 +37,20 @@ namespace Magnum { Used to distinguish construction without creating the underlying OpenGL object. @see @ref NoCreate */ -struct NoCreateT {}; +/* Explicit constructor to avoid ambiguous calls when using {} */ +struct NoCreateT { + #ifndef DOXYGEN_GENERATING_OUTPUT + struct Init{}; + constexpr explicit NoCreateT(Init) {} + #endif +}; /** @brief No creation tag Use for construction without creating the underlying OpenGL object. */ -constexpr NoCreateT NoCreate{}; +constexpr NoCreateT NoCreate{NoCreateT::Init{}}; } diff --git a/src/Magnum/Test/CMakeLists.txt b/src/Magnum/Test/CMakeLists.txt index 9414b6939..c84e74c97 100644 --- a/src/Magnum/Test/CMakeLists.txt +++ b/src/Magnum/Test/CMakeLists.txt @@ -39,6 +39,7 @@ corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum) corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES Magnum) corrade_add_test(ShaderTest ShaderTest.cpp LIBRARIES Magnum) corrade_add_test(VersionTest VersionTest.cpp LIBRARIES Magnum) +corrade_add_test(TagsTest TagsTest.cpp) add_library(ResourceManagerLocalInstanceTestLib ${SHARED_OR_STATIC} ResourceManagerLocalInstanceTestLib.cpp) target_link_libraries(ResourceManagerLocalInstanceTestLib Magnum) diff --git a/src/Magnum/Test/TagsTest.cpp b/src/Magnum/Test/TagsTest.cpp new file mode 100644 index 000000000..48f903c84 --- /dev/null +++ b/src/Magnum/Test/TagsTest.cpp @@ -0,0 +1,48 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Magnum/Tags.h" +#include "Magnum/Magnum.h" +#include "Corrade/TestSuite/Tester.h" + +namespace Magnum { namespace Test { + +struct TagsTest: TestSuite::Tester { + explicit TagsTest(); + + void noDefaultConstructor(); +}; + +TagsTest::TagsTest() { + addTests({&TagsTest::noDefaultConstructor}); +} + +void TagsTest::noDefaultConstructor() { + CORRADE_VERIFY(!std::is_default_constructible::value); +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::TagsTest)