From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 674313857B8E for ; Thu, 19 Oct 2023 11:55:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 674313857B8E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 674313857B8E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697716517; cv=none; b=IGxt58XcS3St6vWu6H5894DebW3+GHFn8N6oRFy5zZk6vPea4VPNdR/Ji2Lqk2kLASj/XrysdKeYLSnHMy2gHcFGTuXZLcBLmGvCxO+QhW5khuSxcCQcS7sOnj9+ADvgeV3qQi9vGcki1mA6eVw6flWLuD/Z9NoEEiqBAJKTXg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697716517; c=relaxed/simple; bh=ij28Fn13VaY1oIZpHqZ6khOM0cGSwe2rLKFK5z5Z/oo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ki3iOn9hYoUL98NV+oJcs066ap48fB+G+LdToHw4G6JrYgoQrfvLY/yCqzEsLyeB5YfglFuki4mE9q1wt8o8XTBJybKB3tNpc5gCucpwQIqhFGWrdhVZ7En+Fagvq1cfQSZi0LQEFqX/grpxmdrxb6oWciJCkjTjtV+vVeS/+RM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697716516; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-to:resent-from:resent-message-id: in-reply-to:in-reply-to:references:references; bh=FSbA7gdMoggIOGaL0amLaFX+0TZkvJQrqSO/pBkx1YA=; b=AHE3N+yGOmqGrd6BqdAFSZKF6f1zbl6mZQ8x7C1krpR2Xc4tzL1CMTZO+Pc3lrY+UvnzPK msfWj1qUhSj16fN5SzU/IphlDcRBsZgXspsvax74hHgnO1T9JMIN9i0oC4FHe+3czBEz/h ZGOkXNQf42vvmYZT28wtOAWQd77kthY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-bXF5qWO9P7uKqeEHPohFeg-1; Thu, 19 Oct 2023 07:55:12 -0400 X-MC-Unique: bXF5qWO9P7uKqeEHPohFeg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C18331C294A4; Thu, 19 Oct 2023 11:55:11 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 853C5503C; Thu, 19 Oct 2023 11:55:11 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 39JBt8ce3765020 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 19 Oct 2023 13:55:09 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 39JBt8tE3765019; Thu, 19 Oct 2023 13:55:08 +0200 Resent-From: Jakub Jelinek Resent-Date: Thu, 19 Oct 2023 13:55:08 +0200 Resent-Message-ID: Resent-To: esok127@gmail.com, gcc-patches@gcc.gnu.org, gcc-help@gcc.gnu.org Date: Thu, 19 Oct 2023 13:50:19 +0200 From: Jakub Jelinek To: esok127@gmail.com Cc: gcc@gcc.gnu.org, gcc-help@gcc.gnu.org Subject: Re: gcc 13.2 is missing warnings? Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Oct 19, 2023 at 07:39:43AM -0400, Eric Sokolowsky via Gcc wrote: > I am using gcc 13.2 on Fedora 38. Consider the following program. > > #include > int main(int argc, char **argv) > { > printf("Enter a number: "); > int num = 0; > scanf("%d", &num); > > switch (num) > { > case 1: > int a = num + 3; > printf("The new number is %d.\n", a); > break; > case 2: > int b = num - 4; > printf("The new number is %d.\n", b); > break; > default: > int c = num * 3; > printf("The new number is %d.\n", c); > break; > } > } > > I would expect that gcc would complain about the declaration of > variables (a, b, and c) within the case statements. When I run "gcc > -Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get > warnings and errors as expected. I do get warnings when using MinGW on > Windows (gcc version 6.3 specifically). Did something change in 13.2? C isn't C++. In particular, the above is valid C23, which is why it is accepted as an extension in older C language versions starting with GCC 11. It is warned about with -pedantic/-Wpedantic and errored on with -pedantic-errors/-Werror=pedantic unless -std=c2x or -std=gnu2x is used. The C++ case is completely different. There labels are allowed before declarations already in C++98, but it is invalid to cross initialization of some variable using the jump to case 2 or default labels above. If you rewrite it as: case 1: int a; a = num + 3; printf("The new number is %d.\n", a); break; case 2: int b; b = num - 4; printf("The new number is %d.\n", b); break; default: int c; c = num * 3; printf("The new number is %d.\n", c); break; it is valid C++ and it won't be diagnosed. Note, this should have been posted to gcc-help instead. Jakub