[cfe-dev] Clang and llvm-gcc disagree on my wrong code

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Dec 15 10:37:58 PST 2010


Hi,

I just broke the build by committing essentially this function:

#include <vector>
void f() {
  std::vector<int> v;
  while (!v.empty) // <-- Note missing ()
    v.pop_back();
}

Clang happily and silently compiled this into:

while.cond:
  br i1 false, label %while.body, label %while.end

GCC doesn't like the bad code at all:

$ llvm-g++ test.cpp
test.cpp: In function ‘void f()’:
test.cpp:4: error: could not convert ‘v.std::vector<_Tp, _Alloc>::empty [with _Tp = int, _Alloc = std::allocator<int>]’ to ‘bool’
test.cpp:4: error: in argument to unary !

Who is right?

/jakob





More information about the cfe-dev mailing list