Index: test/SemaCXX/format-strings.cpp =================================================================== --- test/SemaCXX/format-strings.cpp +++ test/SemaCXX/format-strings.cpp @@ -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 @@ -9,9 +11,13 @@ } 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); } @@ -46,11 +52,19 @@ // 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}} Index: test/SemaCXX/printf-cstr.cpp =================================================================== --- test/SemaCXX/printf-cstr.cpp +++ test/SemaCXX/printf-cstr.cpp @@ -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 @@ -31,12 +33,39 @@ 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@-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("%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 { @@ -49,5 +78,11 @@ 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 } Index: test/SemaCXX/warn-thread-safety-parsing.cpp =================================================================== --- test/SemaCXX/warn-thread-safety-parsing.cpp +++ test/SemaCXX/warn-thread-safety-parsing.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 %s #define LOCKABLE __attribute__ ((lockable)) #define SCOPED_LOCKABLE __attribute__ ((scoped_lockable)) @@ -1266,8 +1268,10 @@ void foo3(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { } void foo4(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu); - static void foo5() EXCLUSIVE_LOCKS_REQUIRED(mu); // \ - // expected-error {{invalid use of member 'mu' in static member function}} + static void foo5() EXCLUSIVE_LOCKS_REQUIRED(mu); +#if __cplusplus <= 199711L + // expected-error@-2 {{invalid use of member 'mu' in static member function}} +#endif template void foo6() EXCLUSIVE_LOCKS_REQUIRED(T::statmu) { } @@ -1461,15 +1465,21 @@ mutable Mutex mu; int a GUARDED_BY(mu); - static int si GUARDED_BY(mu); // \ - // expected-error {{invalid use of non-static data member 'mu'}} + static int si GUARDED_BY(mu); +#if __cplusplus <= 199711L + // expected-error@-2 {{invalid use of non-static data member 'mu'}} +#endif - static void foo() EXCLUSIVE_LOCKS_REQUIRED(mu); // \ - // expected-error {{invalid use of member 'mu' in static member function}} + static void foo() EXCLUSIVE_LOCKS_REQUIRED(mu); +#if __cplusplus <= 199711L + // expected-error@-2 {{invalid use of member 'mu' in static member function}} +#endif friend FooStream& operator<<(FooStream& s, const Foo& f) - EXCLUSIVE_LOCKS_REQUIRED(mu); // \ - // expected-error {{invalid use of non-static data member 'mu'}} + EXCLUSIVE_LOCKS_REQUIRED(mu); +#if __cplusplus <= 199711L + // expected-error@-2 {{invalid use of non-static data member 'mu'}} +#endif };