Explorar el Código

Add static_assert to unusable templates

Ole hace 10 años
padre
commit
897adbc174
Se han modificado 4 ficheros con 20 adiciones y 18 borrados
  1. 1 1
      lib/luwra/functions.hpp
  2. 7 2
      lib/luwra/stack.hpp
  3. 11 15
      lib/luwra/types.hpp
  4. 1 0
      lib/luwra/usertypes.hpp

+ 1 - 1
lib/luwra/functions.hpp

@@ -18,7 +18,7 @@ namespace internal {
 	struct FunctionWrapper {
 		static_assert(
 			sizeof(T) == -1,
-			"The FunctionWrapper template expects a function signature as parameter"
+			"Parameter to FunctionWrapper is not a function signature"
 		);
 	};
 

+ 7 - 2
lib/luwra/stack.hpp

@@ -16,8 +16,13 @@
 LUWRA_NS_BEGIN
 
 namespace internal {
-	template <typename>
-	struct Layout;
+	template <typename T>
+	struct Layout {
+		static_assert(
+			sizeof(T) == -1,
+			"Parameter to Layout is not a function signature"
+		);
+	};
 
 	template <typename R, typename T>
 	struct Layout<R(T)> {

+ 11 - 15
lib/luwra/types.hpp

@@ -28,19 +28,10 @@ using CFunction = lua_CFunction;
  */
 template <typename T>
 struct Value {
-	static_assert(sizeof(T) == -1, "You must not use an unspecialized version of Value");
-
-	/**
-	 * Retrieve the value at position `n`.
-	 */
-	static
-	T read(State*, int);
-
-	/**
-	 * push the value onto the stack.
-	 */
-	static
-	int push(State*, T);
+	static_assert(
+		sizeof(T) == -1,
+		"Parameter to Value is not supported"
+	);
 };
 
 /**
@@ -96,8 +87,13 @@ int push(State* state, T value) {
 #endif
 
 namespace internal {
-	template <typename>
-	struct NumericTransportValue;
+	template <typename T>
+	struct NumericTransportValue {
+		static_assert(
+			sizeof(T) == -1,
+			"Parameter to NumericTransportValue is not a numeric base type"
+		);
+	};
 
 	// Transport unit `Integer`
 	template <>

+ 1 - 0
lib/luwra/usertypes.hpp

@@ -214,6 +214,7 @@ struct Value<U&> {
 
 	static inline
 	T& read(State* state, int n) {
+		// T is unqualified, therefore conversion from T& to U& is allowed
 		return *internal::check_user_type<T>(state, n);
 	}