R
Reetesh Mukul
Hello All,
I compiled the following code:-
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <iostream>
#include <boost/static_assert.hpp>
namespace beta{
struct composition_root{};
template<typename composition>
struct composition_base: composition_root
{
private:
typedef composition C;
typedef typename C::alpha_type alpha_type;
typedef typename C::value_type value_type;
public:
const composition&
derived() const
{
return static_cast<const composition&>(*this);
}
composition&
derived()
{
return static_cast<composition&>(*this);
}
static alpha_type to_alpha(const value_type&)
{
BOOST_STATIC_ASSERT(false);
}
static value_type from_alpha(const alpha_type&)
{
BOOST_STATIC_ASSERT(false);
}
};
struct basic_composition_tag;
}
struct alpha_
{
typedef int alpha_type;
typedef char value_type;
char from_alpha(const alpha_type& x)
{
return 0;
}
int to_alpha(const value_type& x)
{
return 0;
}
};
int main(void)
{
typedef beta::composition_base<alpha_> a;
sizeof(a);
return 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
on msvc(Version 9.0) and gcc 4.3.3.
Behavior:-
a) msvc -- compiles well
b) gcc -- throws error, basically assert failure
Even when I write,
int main(void)
{
//typedef beta::composition_base<alpha_> a;
//sizeof(a);
return 0;
}
The behavior is same.
$1. Is there any problem in BOOST_STATIC_ASSERT ? I will ask in boost
forum for it. Or else you know then please answer it.
$2. Why gcc is complaining error even when template instantiation has
not been done ? (second case)
$3. I understand that any direct use of compositon_base::{to/from }
_alpha is bound to cause problem. But if any code is not touching it,
in that case why compiler is throwing error.
$4. When does static function definition gets instantiated ? If in a
compilation unit, presence of a static function name and definition
anywhere (inside class or outside class) causes it to get instantiated
also, then does the gcc compiler is checking extra for a possible
error in instantiation of a composition_base class.
Please answer.
With Regards,
Reetesh Mukul
I compiled the following code:-
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <iostream>
#include <boost/static_assert.hpp>
namespace beta{
struct composition_root{};
template<typename composition>
struct composition_base: composition_root
{
private:
typedef composition C;
typedef typename C::alpha_type alpha_type;
typedef typename C::value_type value_type;
public:
const composition&
derived() const
{
return static_cast<const composition&>(*this);
}
composition&
derived()
{
return static_cast<composition&>(*this);
}
static alpha_type to_alpha(const value_type&)
{
BOOST_STATIC_ASSERT(false);
}
static value_type from_alpha(const alpha_type&)
{
BOOST_STATIC_ASSERT(false);
}
};
struct basic_composition_tag;
}
struct alpha_
{
typedef int alpha_type;
typedef char value_type;
char from_alpha(const alpha_type& x)
{
return 0;
}
int to_alpha(const value_type& x)
{
return 0;
}
};
int main(void)
{
typedef beta::composition_base<alpha_> a;
sizeof(a);
return 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
on msvc(Version 9.0) and gcc 4.3.3.
Behavior:-
a) msvc -- compiles well
b) gcc -- throws error, basically assert failure
Even when I write,
int main(void)
{
//typedef beta::composition_base<alpha_> a;
//sizeof(a);
return 0;
}
The behavior is same.
$1. Is there any problem in BOOST_STATIC_ASSERT ? I will ask in boost
forum for it. Or else you know then please answer it.
$2. Why gcc is complaining error even when template instantiation has
not been done ? (second case)
$3. I understand that any direct use of compositon_base::{to/from }
_alpha is bound to cause problem. But if any code is not touching it,
in that case why compiler is throwing error.
$4. When does static function definition gets instantiated ? If in a
compilation unit, presence of a static function name and definition
anywhere (inside class or outside class) causes it to get instantiated
also, then does the gcc compiler is checking extra for a possible
error in instantiation of a composition_base class.
Please answer.
With Regards,
Reetesh Mukul