D
dascandy
The following program produces no warnings, no errors, but doesn't do
what I expect it to. I expect it to produce a warning or error. What
does the standard say about this and/or what should it say? Stroustrup
mentions it's an error (The C++ programming language, p343) but
doesn't say whether the standard says so or whether it's
implementation defined.
Both GCC and MSVC return "4 4 40", showing they instantiated the
template at the first oppurtunity and cached the instantiation.
#include <stdio.h>
template <typename T>
struct A {
T o;
};
int sizeofa = sizeof(A<int *>);
template <typename T>
struct A<T *> {
T o[5];
};
int newsizeofa = sizeof(A<int *>);
int main() {
printf("%d, %d %d\n", sizeofa, sizeof(A<int *>),
sizeof(A<double *>));
}
Shouldn't this produce a warning?
what I expect it to. I expect it to produce a warning or error. What
does the standard say about this and/or what should it say? Stroustrup
mentions it's an error (The C++ programming language, p343) but
doesn't say whether the standard says so or whether it's
implementation defined.
Both GCC and MSVC return "4 4 40", showing they instantiated the
template at the first oppurtunity and cached the instantiation.
#include <stdio.h>
template <typename T>
struct A {
T o;
};
int sizeofa = sizeof(A<int *>);
template <typename T>
struct A<T *> {
T o[5];
};
int newsizeofa = sizeof(A<int *>);
int main() {
printf("%d, %d %d\n", sizeofa, sizeof(A<int *>),
sizeof(A<double *>));
}
Shouldn't this produce a warning?