public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mforney at mforney dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/114831] New: typeof doesn't evaluate expression when it has variably modified type in some cases
Date: Wed, 24 Apr 2024 01:48:58 +0000	[thread overview]
Message-ID: <bug-114831-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114831

            Bug ID: 114831
           Summary: typeof doesn't evaluate expression when it has
                    variably modified type in some cases
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mforney at mforney dot org
  Target Milestone: ---

C23 introduced typeof, and 6.7.2.5p4 says

> If the type of the operand is a variably modified type, the operand
> is evaluated; otherwise, the operand is not evaluated.

However, gcc doesn't evaluate the operand when it has variably modified type in
some cases.

Consider the following program:

#include <stdio.h>
int n = 1;
int main(void) {
        int a[n], (*p)[n] = 0;
        typeof(puts("&a is variably-modified"), &a) p1;
        typeof(puts("p is variably-modified"), p) p2;
        typeof(puts("p1 is variably-modified"), p1) p3;
        typeof(puts("p2 is variably-modified"), p2) p4;
}

All four of the typeof operands have the same type, int (*)[n]. But when I run
this program it prints just:

p is variably-modified
p2 is variably-modified

                 reply	other threads:[~2024-04-24  1:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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-114831-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).