re PR c++/52818 (printf format %lf is erroneously rejected by C++11)
authorJason Merrill <jason@redhat.com>
Sun, 15 Apr 2012 17:07:30 +0000 (13:07 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 15 Apr 2012 17:07:30 +0000 (13:07 -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.

From-SVN: r186468

gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/format8.C [new file with mode: 0644]

index 121d94a11a3dcef4b209082d6060011529c14f56..98e496a9034b479bb54132f633f8a167af936fe3 100644 (file)
@@ -1,3 +1,9 @@
+2012-04-15  Jason Merrill  <jason@redhat.com>
+
+       PR c++/52818
+       * c-format.c (CPLUSPLUS_STD_VER): C++11 inherits from C99.
+       (C_STD_NAME): Distinguish between C++98 and C++11.
+
 2012-04-11  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR target/52624
index 9fabc399565ac15fb2bb413f4424d4d9c9484e4a..b9674925204ab08382281788050b98a33a09a8e3 100644 (file)
@@ -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"))
index 1d3e820c2a7cfaaae3e4cff79a75c1383b0751c1..83af0658f009a2e59b2a27c6eb7be0c4fe30acab 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-15  Jason Merrill  <jason@redhat.com>
+
+       PR c++/52818
+       * g++.dg/warn/format8.C: New.
+
 2012-04-15  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/51082
diff --git a/gcc/testsuite/g++.dg/warn/format8.C b/gcc/testsuite/g++.dg/warn/format8.C
new file mode 100644 (file)
index 0000000..ffceb79
--- /dev/null
@@ -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 } }
+}