delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/01/04/13:31:32

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,TW_YG,UNPARSEABLE_RELAY
X-Spam-Check-By: sourceware.org
Message-ID: <4F049AE6.4000508@t-online.de>
Date: Wed, 04 Jan 2012 19:31:02 +0100
From: Christian Franke <Christian DOT Franke AT t-online DOT de>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110928 Firefox/7.0.1 SeaMonkey/2.4.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: mingw64-i686-gcc-4.5.3-4: -Wformat warnings broken in C++
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

When printf/scanf functions from MinGW runtime are selected via 
__USE_MINGW_ANSI_STDIO, then format string checking is broken. This only 
affects the C++ compiler:


$ cygcheck -f /usr/bin/i686-w64-mingw32-g++
mingw64-i686-gcc-g++-4.5.3-4

$ cat testfmt.c
#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h>

void myprintf(const char *, ...)
   __attribute__((format(gnu_printf,1,2)));

int main()
{
   long long x = 42;
   printf("%lld\n", x); // C++: Bogus warning
   myprintf("%lld\n", x); // No warning (OK)
   printf("%I64d\n", x); // Warning (OK)
   return 0;
}

$ i686-w64-mingw32-gcc -Wformat -c testfmt.c
testfmt.c: In function 'main':
testfmt.c:12:3: warning: format '%I64d' expects type 'int', but argument 
2 has type 'long long int'

$ i686-w64-mingw32-g++ -Wformat -c testfmt.c
testfmt.c: In function 'int main()':
testfmt.c:10:21: warning: unknown conversion type character 'l' in format
testfmt.c:10:21: warning: too many arguments for format
testfmt.c:12:22: warning: format '%I64d' expects type 'int', but 
argument 2 has type 'long long int'


Interestingly the bogus warning only occurs for standard functions like 
printf(). These are replaced by inline functions in MinGW stdio.h if 
__USE_MINGW_ANSI_STDIO is set. Probably a subtle bug in the handling of 
functions known by the compiler.


Another observation: Include files from C++ standard library (e.g. 
<string>) now silently set __USE_MINGW_ANSI_STDIO:

/usr/lib/gcc/i686-w64-mingw32/4.5.3/include/c++/i686-w64-mingw32/bits/os_defines.h:
...
#undef __USE_MINGW_ANSI_STDIO
#define __USE_MINGW_ANSI_STDIO 1


Both are new issues not seen in previous releases. If desired, I could 
resend this report to mingw-w64 list.

Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019