Clang and llvm-gcc disagree on my wrong code

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

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?

GCC is right here.

From C++2003 [expr.ref](4):

"The expression can only be used as a left-hand operand of a member
function call."

I attached a much simpler test case. So the problem is the unary "!"
operator, which should reject MemberExprs which refer to non-static
member functions.

Please open a bug report.

Thanks,

memberexpr.cpp (69 Bytes)