Joshua Lehrer Guest
|
Posted: Mon Sep 22, 2003 10:31 pm Post subject: EDG Bug? |
|
|
I believe I have tracked this down to a bug in the EDG front end. The
problem is that it doesn't like the return type to be too complex.
The "choose" template throws it off. If you map the return type
through another class, and hide the "choose" template in the secondary
helper class, then it works fine, as demonstrated in this example:
My Compiler = Compaq C++ V6.5-033
EDG Version = 245?
//a template to "choose" at compile time between
//two types, given a boolean "true" or "false"
template <bool b, typename T1, typename T2> struct choose {
typedef T1 result;
};
template <typename T1, typename T2> struct choose<false,T1,T2> {
typedef T2 result;
};
//an example of a function which does not work
//when the return value is complex.
template <typename T>
typename choose<sizeof(T)==sizeof(int),T,int>::result
does_not_work(const T&);
//a helper class to "hide" the complexity of the return value
template <typename T> struct Helper {
typedef typename choose<sizeof(T)==sizeof(int),T,int>::result
result;
};
//an example of a function which does work with an equally complex
//return value, after mapping this return type through another
//class to make it appear simpler
template <typename T> typename Helper<T>::result works(const T&);
int main(int argc, char **argv) {
works('X');
does_not_work('X');
}
Error:
does_not_work('X');
.....................^
%CXX-E-BADTYPFROMINST, template instantiation resulted in unexpected
function type of "choose<false, char, int>::result (const char &)"
(the meaning of a name may have changed since the template
declaration -- the type of the template is
"choose<::result (const T &)")
detected during instantiation of "does_not_work" based on template
argument <char> at line 30
joshua lehrer
factset research systems
NYSE:FDS
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|