2012/7/11 Simson Garfinkel <[email protected]>

> When I #include <fstream> with mingw64-g++ the PRId64 value is no longer
> interpreted correctly.
>
> Here is the test program:
>
> #define __STDC_FORMAT_MACROS
> #include <inttypes.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <stdint.h>
> #include <fstream>
> int main(int argc,char **argv)
> {
>    uint64_t val=1234567890;
>    printf("%"PRId64"\n",val);
>    exit(0);
> }
>
>
> [simsong@FC17 ~]$ x86_64-w64-mingw32-g++ -Wall x.cpp
> x.cpp: In function 'int main(int, char**)':
> x.cpp:19:29: warning: unknown conversion type character 'l' in format
> [-Wformat]
> x.cpp:19:29: warning: too many arguments for format [-Wformat-extra-args]
> [simsong@FC17 ~]$
>

I can reproduce on my GCC 4.7.1 build. The preprocessor output looks like
this:

int main(int argc,char **argv)
{
   uint64_t val=1234567890;
   printf("%""lld""\n",val);
   exit(0);
}

Which should then be pasted together (if I'm not confusing the order of
phases of translation here) to "%lld".

Note also this code is not C++11 compatible, as the "%"PRId64 is considered
a string literal, thus one single token that is not touched by the
preprocessor (see here for reference:
http://stackoverflow.com/questions/11869593/c99-printf-formatters-vs-c11-user-defined-literalsand
exemplified here:
http://liveworkspace.org/code/63c888c11d29eef2f50733be5a5af5e6). GCC
4.7(.1?) will produce an error in accordance with the C++11 Standard.

The reduced test case for this would thus be:

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <fstream>
int main(int argc,char **argv)
{
   uint64_t val=1234567890;
   printf("%lld\n",val);
   exit(0);
}

Additionally, I can confirm that GCC 4.6.3 has the same erroneous warning,
and Clang 3.1 using the same C and C++ headers does not show a warning.

GCC 4.7.1 on Linux does not show this problem:
http://liveworkspace.org/code/f11d1c9024d2319611b4191f7878f856

That concludes my investigation of this piece of code, in the hope it helps
the real coders to find what is going wrong here.

Ruben



> But if I change the test program to this:
>
> #define __STDC_FORMAT_MACROS
> #include <inttypes.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <stdint.h>
> //#include <fstream>
> int main(int argc,char **argv)
> {
>    uint64_t val=1234567890;
>    printf("%"PRId64"\n",val);
>    exit(0);
> }
>
> Then I have no problem compiling:
>
> [simsong@FC17 ~]$ x86_64-w64-mingw32-g++ -Wall x.cpp
> [simsong@FC17 ~]$
>
>
> [simsong@FC17 ~]$ x86_64-w64-mingw32-g++ --version
> x86_64-w64-mingw32-g++ (GCC) 4.7.0 20120322 (Fedora MinGW 4.7.0-2.fc17)
> Copyright (C) 2012 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> [simsong@FC17 ~]$
>
> This makes no sense to me. Is this a bug?
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to