[cfe-dev] Sudden warnings
Csaba Raduly
rcsaba at gmail.com
Mon Feb 21 08:06:33 PST 2011
Hi all,
Compiling the following snippet:
typedef unsigned long size_t; // line 1
template<class K, class T>
class map {
private:
size_t num_m;
size_t max_m;
static const size_t start_size = 1, factor = 2; // 10
map(const map&);
map& operator=(const map&);
public:
static const size_t max_length = -1; // 15
map() : num_m(0), max_m(0) { }
~map() {
}
void add(const K& , T ) {
if (num_m > 0) {
if (num_m >= max_m) {
if (max_m <= max_length / factor) // 25
max_m *= factor;
else if (max_m < max_length)
max_m = max_length;
}
} else {
max_m = start_size; // 31
}
num_m++;
}
};
class Type;
namespace { // no warnings without it
enum state { PROCESSING = -1, ANSWER_NO, ANSWER_YES };
struct memoizer : private map<Type*, state> {
memoizer() : map<Type*, state>() {}
void remember (Type *t, state s) {
add(t, s);
}
};
}
with
clang version 2.9 (trunk 126116)
Target: x86_64-unknown-linux-gnu
Thread model: posix"
results in the following warnings (errors due to -Werror)
TypeI.cc:15:23: error: variable 'map<Type *,
<anonymous>::state>::max_length' has internal linkage but is not
defined
static const size_t max_length = -1;
^
TypeI.cc:25:22: note: used here
if (max_m <= max_length / factor)
^
TypeI.cc:10:39: error: variable 'map<Type *,
<anonymous>::state>::factor' has internal linkage but is not defined
static const size_t start_size = 1, factor = 2;
^
TypeI.cc:25:35: note: used here
if (max_m <= max_length / factor)
^
TypeI.cc:10:23: error: variable 'map<Type *,
<anonymous>::state>::start_size' has internal linkage but is not
defined
static const size_t start_size = 1, factor = 2;
^
TypeI.cc:31:15: note: used here
max_m = start_size;
^
These warnings were not emitted from clang version 2.9 (trunk 125566).
I think clang is too trigger-happy here. Neither G++ nor Comeau online
reproduced these warnings (Comeau complained about the sign change in
line 15 and some functions being defined but not used).
Csaba
--
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds
More information about the cfe-dev
mailing list