[cfe-dev] boost::ref issue

Matthieu Monrocq matthieu.monrocq at gmail.com
Wed Feb 20 09:33:54 PST 2013


On Tue, Feb 19, 2013 at 7:15 PM, Olivier Goffart <ogoffart at kde.org> wrote:

> On Tuesday 19 February 2013 18:51:16 Laszlo Nagy wrote:
> > Hi All,
> >
> > I'm trying to compile a C++ project with Clang. It compiles with gcc
> > without error, but Clang breaks. Unfortunately could not simplify further
> > and has 'boost' as dependency. I need some help.
> >
> > How can I change the code to compile with clang? And if it is a not
> > expected behavior of Clang, what could be an error report for this?
> >
> > Thanks,
> > Laszlo
> >
>
> I reduced your testcase:
>
>    template <typename T> void ref(T &) { return 8; }
>    struct S { int foo() { return ref(this); } };
>
> I think it is GCC being wrong there.  You should not be able to take a
> reference from 'this'.
>
> You can try boost::cref,  or something like
>   S *that = this; ... boost::ref(that)
>
>
It's always arguable what the "type" of `this` is, seeing as it's an
artifact, but seeing as you cannot reasonable mutate `this` itself (the
pointer, not the pointee), I always think about it as being `T* const`.

-- Matthieu


> --
> Olivier
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130220/3eba7044/attachment.html>


More information about the cfe-dev mailing list