[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] boost::ref issue
From:       Matthieu Monrocq <matthieu.monrocq () gmail ! com>
Date:       2013-02-20 17:33:54
Message-ID: CAKE6RfjRmQWzV3MViCCQ3KbUcvqvA8SicUjuu_SXZ-5Gn-VutQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Tue, Feb 19, 2013 at 7:15 PM, Olivier Goffart <ogoffart@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@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">On Tue, Feb 19, 2013 at 7:15 PM, Olivier Goffart \
<span dir="ltr">&lt;<a href="mailto:ogoffart@kde.org" \
target="_blank">ogoffart@kde.org</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> On Tuesday 19 February 2013 18:51:16 Laszlo Nagy wrote:<br>
&gt; Hi All,<br>
&gt;<br>
&gt; I&#39;m trying to compile a C++ project with Clang. It compiles with gcc<br>
&gt; without error, but Clang breaks. Unfortunately could not simplify further<br>
&gt; and has &#39;boost&#39; as dependency. I need some help.<br>
&gt;<br>
&gt; How can I change the code to compile with clang? And if it is a not<br>
&gt; expected behavior of Clang, what could be an error report for this?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Laszlo<br>
&gt;<br>
<br>
I reduced your testcase:<br>
<br>
   template &lt;typename T&gt; void ref(T &amp;) { return 8; }<br>
   struct S { int foo() { return ref(this); } };<br>
<br>
I think it is GCC being wrong there.  You should not be able to take a<br>
reference from &#39;this&#39;.<br>
<br>
You can try boost::cref,  or something like<br>
  S *that = this; ... boost::ref(that)<br>
<span class="HOEnZb"><font \
color="#888888"><br></font></span></blockquote><div><br>It&#39;s always arguable what \
the &quot;type&quot; of `this` is, seeing as it&#39;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`.<br> <br>-- Matthieu<br> </div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
                solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">
--<br>
Olivier<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" \
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br> \
</font></span></blockquote></div><br>



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic