Explorar o código

Fixed error `forming reference to reference` (issue #495)

Benoit Blanchon %!s(int64=8) %!d(string=hai) anos
pai
achega
cc66618e70
Modificáronse 3 ficheiros con 17 adicións e 12 borrados
  1. 1 0
      CHANGELOG.md
  2. 10 12
      src/ArduinoJson/Data/ValueSetter.hpp
  3. 6 0
      test/CMakeLists.txt

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@ HEAD
 ----
 
 * Fixed error `IsBaseOf is not a member of ArduinoJson::TypeTraits` (issue #495)
+* Fixed error `forming reference to reference` (issue #495)
 
 v5.9.0
 ------

+ 10 - 12
src/ArduinoJson/Data/ValueSetter.hpp

@@ -15,22 +15,21 @@
 namespace ArduinoJson {
 namespace Internals {
 
-template <typename TSource, typename Enable = void>
+template <typename TSourceRef, typename Enable = void>
 struct ValueSetter {
   template <typename TDestination>
-  static bool set(JsonBuffer*, TDestination& destination,
-                  const TSource& source) {
+  static bool set(JsonBuffer*, TDestination& destination, TSourceRef source) {
     destination = source;
     return true;
   }
 };
 
-template <typename TSource>
-struct ValueSetter<TSource, typename TypeTraits::EnableIf<StringTraits<
-                                TSource>::should_duplicate>::type> {
+template <typename TSourceRef>
+struct ValueSetter<TSourceRef, typename TypeTraits::EnableIf<StringTraits<
+                                   TSourceRef>::should_duplicate>::type> {
   template <typename TDestination>
   static bool set(JsonBuffer* buffer, TDestination& destination,
-                  const TSource& source) {
+                  TSourceRef source) {
     const char* copy = buffer->strdup(source);
     if (!copy) return false;
     destination = copy;
@@ -38,12 +37,11 @@ struct ValueSetter<TSource, typename TypeTraits::EnableIf<StringTraits<
   }
 };
 
-template <typename TSource>
-struct ValueSetter<TSource, typename TypeTraits::EnableIf<!StringTraits<
-                                TSource>::should_duplicate>::type> {
+template <typename TSourceRef>
+struct ValueSetter<TSourceRef, typename TypeTraits::EnableIf<!StringTraits<
+                                   TSourceRef>::should_duplicate>::type> {
   template <typename TDestination>
-  static bool set(JsonBuffer*, TDestination& destination,
-                  const TSource& source) {
+  static bool set(JsonBuffer*, TDestination& destination, TSourceRef source) {
     // unsigned char* -> char*
     destination = reinterpret_cast<const char*>(source);
     return true;

+ 6 - 0
test/CMakeLists.txt

@@ -29,6 +29,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
 		-Wstrict-overflow=5
 		-Wundef
 	)
+
+	if(NOT MINGW)
+		add_compile_options(
+			-std=c++98
+		)
+	endif()
 endif()
 
 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")