public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/47932] New: __typeof__ prevents VLA from being evaluated
@ 2011-03-01  4:33 msebor at gmail dot com
  2011-03-01 10:18 ` [Bug c/47932] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gmail dot com @ 2011-03-01  4:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47932

           Summary: __typeof__ prevents VLA from being evaluated
           Product: gcc
           Version: 4.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: msebor@gmail.com


The program below shows that the __typeof__ macro prevents the evaluation of
the variable-length array in a context where one would expect it to be
evaluated according to the documentation:

    The operand of typeof is evaluated for its side effects if and only if it
is an expression of variably modified type or the name of such a type. 

$ cat <<EOF | gcc -xc - && ./a.out
extern int printf(const char*, ...);

#define A(a)   (sizeof (a) / sizeof ((a)[0]))
#define B(a)   (sizeof (a) / sizeof (__typeof__((a)[0])))

int i;

int f() { printf("%s\n", __func__); return i++; }

void g(int n) {
    int a[n][n][n];

    i = 0;
    printf("%zu\n",  A (a[f()]));
    printf("i = %d\n", i);

    i = 0;
    printf("%zu\n",  B (a[f()]));
    printf("i = %d\n", i);
}

int main () {
    g(3);
}
EOF
f
f
3
i = 2
f
3
i = 1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/47932] __typeof__ prevents VLA from being evaluated
  2011-03-01  4:33 [Bug c/47932] New: __typeof__ prevents VLA from being evaluated msebor at gmail dot com
@ 2011-03-01 10:18 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-01 10:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47932

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-01 10:18:51 UTC ---
Fixed in 4.5.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-01 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-01  4:33 [Bug c/47932] New: __typeof__ prevents VLA from being evaluated msebor at gmail dot com
2011-03-01 10:18 ` [Bug c/47932] " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).