Il 08/01/2012 09:35, Eli Friedman ha scritto:
> On Sun, Jan 8, 2012 at 12:12 AM, Abramo Bagnara
> <abramo.bagn...@gmail.com> wrote:
>> $ cat p.cc
>> long f();
>> long g();
>>
>> void m() {
>>  __decltype((int (*)[f()])g()) x;
>> }
>>
>> $ g++ -O2 -S p.cc -o -
>>        .file   "p.cc"
>>        .text
>>        .p2align 4,,15
>>        .globl  _Z1mv
>>        .type   _Z1mv, @function
>> _Z1mv:
>> .LFB0:
>>        .cfi_startproc
>>        rep
>>        ret
>>        .cfi_endproc
>> .LFE0:
>>        .size   _Z1mv, .-_Z1mv
>>        .ident  "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
>>        .section        .note.GNU-stack,"",@progbits
> 
> That's... interesting... what happens if you try to return sizeof(*x)?

It calls f() (but not g()), just like clang does. The difference between
the two compilers is that clang always generates the call to f while gcc
generates it only when needed.

However neither of them evaluates the decltype expression but only the
vla type size. This can be verified by the missing call to g.

$ cat p.cc
long f();
long g();

long m() {
  __decltype((int (*)[f()])g()) x;
  return sizeof(*x);
}

$ g++ -O2 -S p.cc -o -
        .file   "p.cc"
        .text
        .p2align 4,,15
        .globl  _Z1mv
        .type   _Z1mv, @function
_Z1mv:
.LFB0:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        call    _Z1fv
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        salq    $2, %rax
        ret
        .cfi_endproc
.LFE0:
        .size   _Z1mv, .-_Z1mv
        .ident  "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
        .section        .note.GNU-stack,"",@progbits
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to