[cfe-dev] Clang and llvm-gcc disagree on my wrong code
Peter Collingbourne
peter at pcc.me.uk
Wed Dec 15 11:18:17 PST 2010
On Wed, Dec 15, 2010 at 10:37:58AM -0800, Jakob Stoklund Olesen wrote:
> 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,
--
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memberexpr.cpp
Type: text/x-c++src
Size: 69 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101215/9b1626b4/attachment.cpp>
More information about the cfe-dev
mailing list