From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 907433849ACF for ; Fri, 19 Apr 2024 19:57:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 907433849ACF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 907433849ACF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713556638; cv=none; b=lkUCWE2DN719SoBsPhe6A92AILAxOnPS0AVSw9Z5E5Qsi1eoa6QBYZ1Uq3KByW2AEpNH0LqY/W8uQ5GAe5bet5utfR/2ntoIQA4RakV5fzE7QTZDJjiplxpGUoh/KIyIv8yXjwIytpkpa+WsQWvCKZ5gMqzcsTa3sZuDQUAv100= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713556638; c=relaxed/simple; bh=QzmCQSA0zVcMhrZEq3cB4Q5e8hAoWupJ+t9+Zjt0gwM=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=BSz/uAuJoAIHKMKm5e/qas0It9ylRo9FrpMRLBermR8nG0iqPO2vv9b37BBMwSLkc3acJB1dqp7oJHPQmAF3G4O8MR5YpHsOGO1jWS1/JQx0iS1FHkwKs4XAHyVSV7/WilcEAMfLde1MCJJ1XSYwaut74jJ+GhsxudTNvMBRpXQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-419db6066d4so1255485e9.0 for ; Fri, 19 Apr 2024 12:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713556626; x=1714161426; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=o9y81gakq/5PDuCdq1C6ZwAO4mg2sWlF/Uat9B5E3gY=; b=F6WuCT8rIZ1YdAV1Ouy/Ie0fPqb2eQy1UehC2A6BWDBs92VsHs+vDTrqcEF1ecaGJS UcRzxvLpkKWzj1Obrok5PR4NBr37haOmQRIXot6fZJyhdcrPfX49CrrlTbplakRABT2M 9onCXD2EYauX/pnOOkSKbLm/HstNVyR5z31suCdOHn+VRYj8vRCsaFHdxwg07K2MEtAS 4qcNJKpWU47l2ccno935gaTcUhcXi1tFsONNLzo7cyicHMbrrdmatd+0IE01s1YmMmPp ao3RP9u+wqezUZknrZbF0vbkp05/4juwX+/LksiADjtihfs/ekGVd8FmO1bu9sF5J+iN xYkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713556626; x=1714161426; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=o9y81gakq/5PDuCdq1C6ZwAO4mg2sWlF/Uat9B5E3gY=; b=S04KxWYC1jV1Omoj8Y9gEFJXIS0No0cq+aVKxLG/rNoqUPG7KlV+aSOSCoHnO+0Rl6 R2/bja0+Jum/WZMDtadLnktU3f/f4rsVOacR/l76BTq2g/6U1+SGNVdpq4DuexkSeqHo sjzjSDLX2ch+0l7qgG395W0bFhjRbEG8x9Nq/eKb5p0k1s1JO9aF10S/YGc41pQmhhHi Llu60MgJLtI4Txx6VPnngtFopO6awyZlgLzZUFps3v2UIQnj4sz8eWHYu9jCJbgeMNFD TSJeOvfVbIOAa99FWIe2x/W3AK3+C/F1gluYboo40MIEbn20bn4trJ5bn1PqrOTWnkOX UZ1A== X-Gm-Message-State: AOJu0YwJrxB2TnMi2DyyT9J1lSTn28V088PHvpCdLYnTSEktXS8BWYrJ 01J4jD3GeQtSZuOx+4Hw5ZN6hvNF8yVUz30J9QqvSRP5KAW86ArPuZ9ddMy4ixuwgODBFkgp1pp nLeJBBOeIVOL/4wLMRTtAfLliO5tWUZzq X-Google-Smtp-Source: AGHT+IGg+e5ZqjKL2tyYdz5ZPwTHSahSXnIwlt/8rIdJaSrjKxxJv4g483AEaEQHK2e/CAdj34zDDC/baez3PkeHDZg= X-Received: by 2002:a5d:4d4b:0:b0:33e:7fbc:caea with SMTP id a11-20020a5d4d4b000000b0033e7fbccaeamr2216633wru.34.1713556625613; Fri, 19 Apr 2024 12:57:05 -0700 (PDT) MIME-Version: 1.0 From: Qun-Ying Date: Fri, 19 Apr 2024 12:56:46 -0700 Message-ID: Subject: Why one form have no warning the other forms have warning when using -Wformat=2 To: gcc@gcc.gnu.org Content-Type: multipart/mixed; boundary="000000000000f902170616787db9" X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000f902170616787db9 Content-Type: text/plain; charset="UTF-8" Hi, While testing with -Wformat=2, I encountered the following behaviour: Please see the attached simple C file (tested on gcc 11.2.0/gcc 13.2.1), both give the same warning (clang (17.0.6/gives no warning, although I am not really sure they have the same effect with the flags). It gives the following error when compiling with "gcc -c -Wformat=2 fmt-test.c" fmt-test.c:9:9: warning: format not a string literal, argument types not checked [-Wformat-nonliteral] The strange thing is that, when the fmt_str is defined as "const char fmt_str[]", no warning is given, while defined it as "const char *fmt_str" or "const char *const fmt_str", warning is given. Most of the time, I would prefer fmt_str to be "const char *" or "const char *const" to ensure it is not mutable. From my view, the compiler should either give no warning (I would prefer this) or give warning for all cases. -- Qun-Ying --000000000000f902170616787db9 Content-Type: text/x-csrc; charset="US-ASCII"; name="fmt-test.c" Content-Disposition: attachment; filename="fmt-test.c" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lv72wbe30 I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7Ci8v CWNvbnN0IGNoYXIgc3RyX2ZtdFtdID0gImhlbGxvIHdvcmxkOiAlZFxuIjsgLyogT0sgKi8KLy8J Y29uc3QgY2hhciAqc3RyX2ZtdCA9ICJoZWxsbyB3b3JsZDogJWRcbiI7IC8qIFdhcm5pbmcgKi8K CWNvbnN0IGNoYXIgKiBjb25zdCBzdHJfZm10ID0gImhlbGxvIHdvcmxkOiAlZFxuIjsgLyogV2Fy bmluZyAqLwoKCXByaW50ZihzdHJfZm10LCAxKTsKCXJldHVybiAwOwp9Cg== --000000000000f902170616787db9--