[lldb-dev] invalid use of 'this' outside of a non-static member function

Zachary Turner zturner at google.com
Wed Jan 7 10:57:30 PST 2015


The canonical Windows command line debugger solves this by having two
different evaluation modes.  One for C and one for C++.  I believe C++ is
always the default, but C evaluation mode can be forced by enclosing an
expression in special delimiters.  You can toggle the evaluation mode
multiple times inside the same expression as well.  So you can have a
single expression where different pieces of it are evaluated differently.

Not a language lawyer, but it seems like other stuff would be broken
besides just variables named 'this'.  Are there any other known causes of
incorrect evaluation in C frames due to using a C++ evaluation mode?

On Wed Jan 07 2015 at 10:51:43 AM Greg Clayton <gclayton at apple.com> wrote:

> All expressions are compiled in C++ mode and thus the restriction.
>
> There are a few solutions:
> 1 - make expressions match the current language of the current frame. So
> if your function was a C function, you will be restricted from using C++ in
> your expression
> 2 - rename your "this" and benefit from the C++ abilities of the
> expression parser
>
> I personally really like the ability to use "auto" and all of the C++11
> constructs in any expression:
>
> (lldb) expr for (auto x = 0; x < my_renamed_this; ++x) { ... }
>
> So I see the problem with C expressions, but I would rather not limit you
> from being able to access your C++ code from a C function by limiting the
> language based on where you are stopped.
>
> Greg
>
> > On Jan 7, 2015, at 7:16 AM, mobi phil <mobi at mobiphil.com> wrote:
> >
> > Hi,
> >
> > The compiler accepted it, so IMHO LLDB should not complain about it.
> >
> > I can rename this "this" inside a C function, but it is very likely that
> other people would name a variable "this" inside C code.
> >
> >
> > rgrds,
> > mobi phil
> >
> >
> > _______________________________________________
> > lldb-dev mailing list
> > lldb-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
>
>
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20150107/28fc20d5/attachment.html>


More information about the lldb-dev mailing list