public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/47932] New: __typeof__ prevents VLA from being evaluated
Date: Tue, 01 Mar 2011 04:33:00 -0000	[thread overview]
Message-ID: <bug-47932-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2011-03-01  4:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01  4:33 msebor at gmail dot com [this message]
2011-03-01 10:18 ` [Bug c/47932] " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-47932-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).