r294979 - [Test] Make Lit tests C++11 compatible - printf format string
Charles Li via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 13 10:57:07 PST 2017
Author: lcharles
Date: Mon Feb 13 12:57:06 2017
New Revision: 294979
URL: http://llvm.org/viewvc/llvm-project?rev=294979&view=rev
Log:
[Test] Make Lit tests C++11 compatible - printf format string
Different diagnostics when format string does not match
actual arg type.
This commit contains the first 2 of 3 tests reviewed in D29685
Modified:
cfe/trunk/test/SemaCXX/format-strings.cpp
cfe/trunk/test/SemaCXX/printf-cstr.cpp
Modified: cfe/trunk/test/SemaCXX/format-strings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings.cpp?rev=294979&r1=294978&r2=294979&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/format-strings.cpp (original)
+++ cfe/trunk/test/SemaCXX/format-strings.cpp Mon Feb 13 12:57:06 2017
@@ -1,4 +1,6 @@
// 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>
@@ -9,9 +11,13 @@ extern int vprintf(const char *restrict,
}
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 at -2 {{'a' length modifier is not supported by ISO C}}
+#else
+ // expected-warning at -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);
}
@@ -46,11 +52,19 @@ void h(int *i) {
// 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 at -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 at -2 {{null from a constant boolean}}
+#else
+ // expected-error at -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}}
Modified: cfe/trunk/test/SemaCXX/printf-cstr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/printf-cstr.cpp?rev=294979&r1=294978&r2=294979&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/printf-cstr.cpp (original)
+++ cfe/trunk/test/SemaCXX/printf-cstr.cpp Mon Feb 13 12:57:06 2017
@@ -1,4 +1,6 @@
// 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>
@@ -31,12 +33,39 @@ void pod_test() {
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(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, hcs);
+#if __cplusplus <= 199711L
+ // expected-warning at -2 {{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}}
+ // expected-note at -3 {{did you mean to call the c_str() method?}}
+#else
+ // expected-warning at -5 {{format specifies type 'char *' but the argument has type 'HasCStr'}}
+#endif
+
+ printf("%d: %s\n", n, hncs);
+#if __cplusplus <= 199711L
+ // expected-warning at -2 {{cannot pass non-POD object of type 'HasNoCStr' to variadic function; expected type from format string was 'char *'}}
+#else
+ // expected-warning at -4 {{format specifies type 'char *' but the argument has type 'HasNoCStr'}}
+#endif
+
+ sprintf(str, "%d: %s", n, hcs);
+#if __cplusplus <= 199711L
+ // expected-warning at -2 {{cannot pass non-POD object of type 'HasCStr' to variadic function; expected type from format string was 'char *'}}
+ // expected-note at -3 {{did you mean to call the c_str() method?}}
+#else
+ // expected-warning at -5 {{format specifies type 'char *' but the argument has type 'HasCStr'}}
+#endif
+
+ printf(formatString, hcs, hncs);
+#if __cplusplus <= 199711L
+ // expected-warning at -2 {{cannot pass object of non-POD type 'HasCStr' through variadic function}}
+ // expected-warning at -3 {{cannot pass object of non-POD type 'HasNoCStr' through variadic function}}
+#endif
+
+ printf(extstr, hcs, n);
+#if __cplusplus <= 199711L
+ // expected-warning at -2 {{cannot pass object of non-POD type 'HasCStr' through variadic function}}
+#endif
}
struct Printf {
@@ -49,5 +78,11 @@ void constructor_test() {
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 at -2 {{cannot pass non-POD object of type 'HasCStr' to variadic constructor; expected type from format string was 'char *'}}
+ // expected-note at -3 {{did you mean to call the c_str() method?}}
+#else
+ // expected-warning at -5 {{format specifies type 'char *' but the argument has type 'HasCStr'}}
+#endif
}
More information about the cfe-commits
mailing list