amend eaa53b0 and #1232 to compile with clang++ by avoiding first pass instanciation of intentionally invalid templates - refs #985

This commit is contained in:
Dane Springmeyer 2012-05-29 15:28:35 -07:00
parent eaa53b0904
commit 5feb9750e5

View file

@ -34,21 +34,19 @@ namespace mapnik
{
MAPNIK_DECL std::string to_expression_string(expr_node const& node);
// Dummy types that are used to trigger nice (with gcc at least)
// compilation error when to_expression_string is misused.
enum expr_node_ref_ {};
enum expr_node_ptr_ {};
// The following two templates should prevent accidentally passing
// a pointer (either raw or shared) as the argument. Without them,
// the compiler would construct a temporary expr_node(bool) using
// implicit pointer-to-bool conversion, thus any non-null pointer
// would yield "true".
/*
The following two templates are intentionally invalid and will prompt
a compile error if ever instanciated. This should prevent accidentally
passing a pointer (either raw or shared) as the argument. Without them,
the compiler could construct a temporary expr_node(bool) using
implicit pointer-to-bool conversion, thus any non-null pointer
would yield "true".
*/
template <typename T>
std::string to_expression_string(T const* x)
{
expr_node_ref_ invalid_argument_type = expr_node_ptr_();
x = 0;
throw std::logic_error("to_expression_string() called with pointer argument");
return std::string();
}
@ -56,7 +54,7 @@ std::string to_expression_string(T const* x)
template <typename T>
std::string to_expression_string(boost::shared_ptr<T> const& x)
{
expr_node_ref_ invalid_argument_type = expr_node_ptr_();
x = 0;
throw std::logic_error("to_expression_string() called with pointer argument");
return std::string();
}