diff mbox

C++ PATCH for c++/52818 (%ld in C++11)

Message ID 4F8AFF13.3090500@redhat.com
State New
Headers show

Commit Message

Jason Merrill April 15, 2012, 5:02 p.m. UTC
C++11 inherits from C99, so we shouldn't complain about using %ld in 
that mode.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 4433edb6e099fbb6251c1ab76266108c45582ebc
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Apr 13 16:03:59 2012 -0400

    	PR c++/52818
    	* c-format.c (CPLUSPLUS_STD_VER): C++11 inherits from C99.
    	(C_STD_NAME): Distinguish between C++98 and C++11.

diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 9fabc39..b967492 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -334,7 +334,7 @@  decode_format_attr (tree args, function_format_info *info, int validated_p)
 
 /* The C standard version C++ is treated as equivalent to
    or inheriting from, for the purpose of format features supported.  */
-#define CPLUSPLUS_STD_VER	STD_C94
+#define CPLUSPLUS_STD_VER	(cxx_dialect < cxx11 ? STD_C94 : STD_C99)
 /* The C standard version we are checking formats against when pedantic.  */
 #define C_STD_VER		((int) (c_dialect_cxx ()		   \
 				 ? CPLUSPLUS_STD_VER			   \
@@ -345,7 +345,8 @@  decode_format_attr (tree args, function_format_info *info, int validated_p)
    pedantic.  FEATURE_VER is the version in which the feature warned out
    appeared, which is higher than C_STD_VER.  */
 #define C_STD_NAME(FEATURE_VER) (c_dialect_cxx ()		\
-				 ? "ISO C++"			\
+				 ? (cxx_dialect < cxx11 ? "ISO C++98" \
+				    : "ISO C++11")		\
 				 : ((FEATURE_VER) == STD_EXT	\
 				    ? "ISO C"			\
 				    : "ISO C90"))
diff --git a/gcc/testsuite/g++.dg/warn/format8.C b/gcc/testsuite/g++.dg/warn/format8.C
new file mode 100644
index 0000000..ffceb79
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/format8.C
@@ -0,0 +1,7 @@ 
+// PR c++/52818
+// { dg-options "-pedantic-errors -Wformat" }
+
+extern "C" int printf (const char *, ...);
+void f() {
+  printf("%lf", 0.0);		// { dg-warning "%lf" "" { target c++98 } }
+}