[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
statics / enums still broken - any fix in sight?
From: |
Markus Werle |
Subject: |
statics / enums still broken - any fix in sight? |
Date: |
Tue, 20 May 2003 11:24:12 +0200 |
User-agent: |
KNode/0.6.1 |
Hi!
I still encounter (severe) problems with compile time constants,
even in today's cvs:
g++ (GCC) 3.4 20030520 (experimental)
Both code pieces compile fine with Intel-7.0 and option -ansi,
so they either are gcc bugs or the grey zone of the standard.
Please (!) tell me whether there are fixes in sight for this or
whether I have to take the tedious task to put workarounds
everywhere in my code.
Since it stresses compiler's template section at maximum
I propose the daixtrose lib (http://daixtrose.sf.net)
as a benchmark for g++. Try to compile this and then fix things
like those below (or sue me for not writing compliant code ;-)):
---------------------------------------------------------------
#include <iostream>
template<class T>
class has_member_disambiguation // Thanks to Paul Mensonides
{
protected:
template<class U> static char check(typename U::Disambiguation*);
template<class U> static char (& check(...))[2];
public:
enum { value = (sizeof(check<T>(0)) == 1) };
};
struct A
{
typedef double Disambiguation;
};
struct B {};
int main()
{
std::cerr << has_member_disambiguation<A>::value << std::endl;
std::cerr << has_member_disambiguation<B>::value << std::endl;
}
------------------------------------------------------------------
GCC-3.4-Bugs.C: In instantiation of `has_member_disambiguation<A>':
GCC-3.4-Bugs.C:24: instantiated from here
GCC-3.4-Bugs.C:11: error: invalid use of
undefined type `class has_member_disambiguation<A>'
GCC-3.4-Bugs.C:5: error: declaration of `
class has_member_disambiguation<A>'
GCC-3.4-Bugs.C:11: error: enumerator
value for `value' not integer constant
GCC-3.4-Bugs.C: In instantiation of `has_member_disambiguation<B>':
GCC-3.4-Bugs.C:25: instantiated from here
GCC-3.4-Bugs.C:11: error: invalid use of
undefined type `class has_member_disambiguation<B>'
GCC-3.4-Bugs.C:5: error: declaration of `
class has_member_disambiguation<B>'
GCC-3.4-Bugs.C:11: error: enumerator
value for `value' not integer constant
The next one I think I maybe already reported, but anyway,
it _should_ work, but does not:
--------------------------------------------------------
template <class T1, class T2>
struct Is { static const bool SameType = false; };
template <class T>
struct Is<T, T> { static const bool SameType = true; };
#define SAME_TYPE(T1, T2) Is<T1, T2>::SameType
template <class T>
struct Test
{
static const bool test1 = SAME_TYPE(double, T);
static const bool test2 = false;
static const bool result = test1 || test2;
};
int main() {
Test<double> T1;
}
---------------------------------------------------------
g++ ~/hp-home/C++/EXPERIMENTAL/GCC-3.4-CannotAppearInConstantExpr.C
/home/markus/hp-home/C++/EXPERIMENTAL/GCC-3.4-CannotAppearInConstantExpr.C:16:
error: `
Test<T>::test1' cannot appear in a constant-expression
IMHO it can.
best regards,
Markus
--
Compile time analytic differentiation?
Yes, at http://daixtrose.sourceforge.net/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- statics / enums still broken - any fix in sight?,
Markus Werle <=