[PATCH] D26843: Make sizeof expression context partially evaluated

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 18 12:30:48 PST 2016


FYI I took the example from the [C++1z standard](
http://eel.is/c++draft/expr.prim.id#2)

> [expr.prim.id]p2:
> An id-expression that denotes a non-static data member or non-static
member function of a class can only
> be used [...] if that id-expression denotes a non-static data member and
it appears in an unevaluated operand.

Here is another example that works in C++03 as well as C++11:

```
template <class T>
T foo() {
  _Static_assert(sizeof(T) != sizeof(T),
                 "foo can not appear in a potentially evaluated
expression");
}
typedef __typeof(foo<int>()) T; // OK. Unevaluated context.
int x = sizeof(foo<int>()); // Ill-formed. Triggers assertion because a
definition is required.
```

/Eric

On Fri, Nov 18, 2016 at 12:52 PM, Paulo Matos via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

>
>
> On 18/11/16 20:30, Aaron Ballman wrote:
> > On Fri, Nov 18, 2016 at 2:22 PM, Paulo Matos via cfe-commits
> > <cfe-commits at lists.llvm.org> wrote:
> >> pmatos added a comment.
> >>
> >> Apologies if I am being shallow and wasting your time but
> `sizeof(T::m)` doesn't compile at the moment with clang trunk. Using the
> same service you used before <http://melpon.org/wandbox/
> permlink/C4pCnoVGmS0qBUxf>.
> >
> > Compile for C++11 instead of C++03.
> >
>
> OK, I can see the problem. Interestingly, the error you get with the
> patch and c++11 is the same you used to get with c++03.
>
> I will take a look at this.
>
> --
> Paulo Matos
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161118/315b4fca/attachment-0001.html>


More information about the cfe-commits mailing list