// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++11 %s
#include <stdarg.h>
}
void f(char **sp, float *fp) {
- scanf("%as", sp); // expected-warning{{'a' length modifier is not supported by ISO C}}
+ scanf("%as", sp);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{'a' length modifier is not supported by ISO C}}
+#else
+ // expected-warning@-4 {{format specifies type 'float *' but the argument has type 'char **'}}
+#endif
- // TODO: Warn that the 'a' conversion specifier is a C++11 feature.
printf("%a", 1.0);
scanf("%afoobar", fp);
}
// Test handling __null for format string literal checking.
extern "C" {
int test_null_format(const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+#if __cplusplus >= 201103L
+ // expected-note@-2 {{candidate function not viable: no known conversion from 'bool' to 'const char *' for 1st argument}}
+#endif
}
void rdar8269537(const char *f)
{
- test_null_format(false); // expected-warning {{null from a constant boolean}}
+ test_null_format(false);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{null from a constant boolean}}
+#else
+ // expected-error@-4 {{no matching function for call to 'test_null_format'}}
+#endif
test_null_format(0); // no-warning
test_null_format(__null); // no-warning
test_null_format(f); // expected-warning {{not a string literal}}
// RUN: %clang_cc1 -fsyntax-only -Wformat -verify %s -Wno-error=non-pod-varargs
+// RUN: %clang_cc1 -fsyntax-only -Wformat -verify -std=c++98 %s -Wno-error=non-pod-varargs
+// RUN: %clang_cc1 -fsyntax-only -Wformat -verify -std=c++11 %s -Wno-error=non-pod-varargs
#include <stdarg.h>
int n = 10;
printf("%d: %s\n", n, hcs.c_str());
- printf("%d: %s\n", n, hcs); // expected-warning{{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}} expected-note{{did you mean to call the c_str() method?}}
- printf("%d: %s\n", n, hncs); // expected-warning{{cannot pass non-POD object of type 'HasNoCStr' to variadic function; expected type from format string was 'char *'}}
- sprintf(str, "%d: %s", n, hcs); // expected-warning{{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}} expected-note{{did you mean to call the c_str() method?}}
+ printf("%d: %s\n", n, hcs);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}}
+ // expected-note@-3 {{did you mean to call the c_str() method?}}
+#else
+ // expected-warning@-5 {{format specifies type 'char *' but the argument has type 'HasCStr'}}
+#endif
- printf(formatString, hcs, hncs); // expected-warning{{cannot pass object of non-POD type 'HasCStr' through variadic function}} expected-warning{{cannot pass object of non-POD type 'HasNoCStr' through variadic function}}
- printf(extstr, hcs, n); // expected-warning{{cannot pass object of non-POD type 'HasCStr' through variadic function}}
+ printf("%d: %s\n", n, hncs);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{cannot pass non-POD object of type 'HasNoCStr' to variadic function; expected type from format string was 'char *'}}
+#else
+ // expected-warning@-4 {{format specifies type 'char *' but the argument has type 'HasNoCStr'}}
+#endif
+
+ sprintf(str, "%d: %s", n, hcs);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}}
+ // expected-note@-3 {{did you mean to call the c_str() method?}}
+#else
+ // expected-warning@-5 {{format specifies type 'char *' but the argument has type 'HasCStr'}}
+#endif
+
+ printf(formatString, hcs, hncs);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{cannot pass object of non-POD type 'HasCStr' through variadic function}}
+ // expected-warning@-3 {{cannot pass object of non-POD type 'HasNoCStr' through variadic function}}
+#endif
+
+ printf(extstr, hcs, n);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{cannot pass object of non-POD type 'HasCStr' through variadic function}}
+#endif
}
struct Printf {
const char str[] = "test";
HasCStr hcs(str);
Printf p("%s %d %s", str, 10, 10); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
- Printf q("%s %d", hcs, 10); // expected-warning {{cannot pass non-POD object of type 'HasCStr' to variadic constructor; expected type from format string was 'char *'}} expected-note{{did you mean to call the c_str() method?}}
+ Printf q("%s %d", hcs, 10);
+#if __cplusplus <= 199711L
+ // expected-warning@-2 {{cannot pass non-POD object of type 'HasCStr' to variadic constructor; expected type from format string was 'char *'}}
+ // expected-note@-3 {{did you mean to call the c_str() method?}}
+#else
+ // expected-warning@-5 {{format specifies type 'char *' but the argument has type 'HasCStr'}}
+#endif
}