From 64a1a81e76b48ade6773887323476b2a6fb72c38 Mon Sep 17 00:00:00 2001 From: Charles Li Date: Wed, 13 Apr 2016 20:00:45 +0000 Subject: [PATCH] Lit C++11 Compatibility Patch #7 13 tests have been updated for C++11 compatibility. Differential Revision: http://reviews.llvm.org/D19068 llvm-svn: 266239 --- .../test/CXX/class.access/class.access.dcl/p1.cpp | 205 ++++++++++++++++++--- .../test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp | 76 ++++++-- .../test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp | 14 +- clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp | 17 +- clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp | 9 +- clang/test/CodeGenCXX/debug-info-static-member.cpp | 6 + clang/test/SemaCXX/dcl_init_aggr.cpp | 80 ++++++-- clang/test/SemaCXX/type-convert-construct.cpp | 19 +- clang/test/SemaCXX/vararg-non-pod.cpp | 112 +++++++++-- clang/test/SemaTemplate/class-template-spec.cpp | 47 ++++- clang/test/SemaTemplate/instantiate-cast.cpp | 11 +- clang/test/SemaTemplate/instantiate-expr-4.cpp | 12 ++ .../test/SemaTemplate/instantiate-member-class.cpp | 16 +- 13 files changed, 527 insertions(+), 97 deletions(-) diff --git a/clang/test/CXX/class.access/class.access.dcl/p1.cpp b/clang/test/CXX/class.access/class.access.dcl/p1.cpp index aab5fff..118ab9e 100644 --- a/clang/test/CXX/class.access/class.access.dcl/p1.cpp +++ b/clang/test/CXX/class.access/class.access.dcl/p1.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s // This is just the test for [namespace.udecl]p4 with 'using' // uniformly stripped out. @@ -24,10 +26,33 @@ namespace test0 { } class Test0 { - NonClass::type; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} - NonClass::hiding; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} - NonClass::union_member; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} - NonClass::enumerator; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} + NonClass::type; // expected-error {{not a class}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + NonClass::hiding; // expected-error {{not a class}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + NonClass::union_member; // expected-error {{not a class}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + NonClass::enumerator; // expected-error {{not a class}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif }; } @@ -43,11 +68,39 @@ namespace test1 { }; struct B : A { - A::type; // expected-warning {{access declarations are deprecated}} - A::hiding; // expected-warning {{access declarations are deprecated}} - A::union_member; // expected-warning {{access declarations are deprecated}} - A::enumerator; // expected-warning {{access declarations are deprecated}} - A::tagname; // expected-warning {{access declarations are deprecated}} + A::type; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + A::hiding; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::union_member; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::enumerator; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::tagname; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif void test0() { type t = 0; @@ -86,11 +139,40 @@ namespace test2 { }; template struct B : A { - A::type; // expected-warning {{access declarations are deprecated}} - A::hiding; // expected-warning {{access declarations are deprecated}} - A::union_member; // expected-warning {{access declarations are deprecated}} - A::enumerator; // expected-warning {{access declarations are deprecated}} - A::tagname; // expected-warning {{access declarations are deprecated}} + A::type; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::hiding; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::union_member; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::enumerator; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::tagname; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif void test0() { type t = 0; @@ -131,11 +213,40 @@ namespace test3 { }; template struct B : A { - A::type; // expected-error {{dependent using declaration resolved to type without 'typename'}} // expected-warning {{access declarations are deprecated}} - A::hiding; // expected-warning {{access declarations are deprecated}} - A::union_member; // expected-warning {{access declarations are deprecated}} - A::enumerator; // expected-warning {{access declarations are deprecated}} - A::tagname; // expected-error {{dependent using declaration resolved to type without 'typename'}} // expected-warning {{access declarations are deprecated}} + A::type; // expected-error {{dependent using declaration resolved to type without 'typename'}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::hiding; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::union_member; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::enumerator; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + A::tagname; // expected-error {{dependent using declaration resolved to type without 'typename'}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif // FIXME: re-enable these when the various bugs involving tags are fixed #if 0 @@ -186,14 +297,54 @@ namespace test4 { // We should be able to diagnose these without instantiation. template struct C : Base { - InnerNS::foo; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}} - Base::bar; // expected-error {{no member named 'bar'}} expected-warning {{access declarations are deprecated}} - Unrelated::foo; // expected-error {{not a base class}} expected-warning {{access declarations are deprecated}} - C::foo; // legal in C++03 // expected-warning {{access declarations are deprecated}} - Subclass::foo; // legal in C++03 // expected-warning {{access declarations are deprecated}} - - int bar(); //expected-note {{target of using declaration}} - C::bar; // expected-error {{refers to its own class}} expected-warning {{access declarations are deprecated}} + InnerNS::foo; // expected-error {{not a class}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + Base::bar; // expected-error {{no member named 'bar'}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + Unrelated::foo; // expected-error {{not a base class}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + + C::foo; // legal in C++03 +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} + // expected-error@-5 {{using declaration refers to its own class}} +#endif + + Subclass::foo; // legal in C++03 +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} + // expected-error@-5 {{using declaration refers into 'Subclass::', which is not a base class of 'C'}} +#endif + + int bar(); +#if __cplusplus <= 199711L + //expected-note@-2 {{target of using declaration}} +#endif + C::bar; +#if __cplusplus <= 199711L + // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}} +#else + // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}} +#endif + // expected-error@-6 {{using declaration refers to its own class}} }; } diff --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp index 4fbc45a..21399b6 100644 --- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp @@ -1,4 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + // This test creates cases where implicit instantiations of various entities // would cause a diagnostic, but provides expliict specializations for those @@ -16,7 +19,10 @@ struct NonDefaultConstructible { // -- function template namespace N0 { - template void f0(T) { // expected-note{{here}} + template void f0(T) { +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif T t; } @@ -36,7 +42,11 @@ namespace N1 { template<> void N0::f0(long) { } // expected-error{{does not enclose namespace}} } -template<> void N0::f0(double); // expected-warning{{C++11 extension}} +template<> void N0::f0(double); +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of function template specialization of 'f0' outside namespace 'N0' is a C++11 extension}} +#endif + template<> void N0::f0(double) { } struct X1 { @@ -49,21 +59,39 @@ struct X1 { namespace N0 { template -struct X0 { // expected-note 2{{here}} - static T member; // expected-note{{here}} +struct X0 { // expected-note {{explicitly specialized declaration is here}} +#if __cplusplus <= 199711L +// expected-note@-2 {{explicitly specialized declaration is here}} +#endif + static T member; +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif - void f1(T t) { // expected-note{{explicitly specialized declaration is here}} + void f1(T t) { +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif t = 17; } - struct Inner : public T { }; // expected-note 3{{here}} + struct Inner : public T { }; // expected-note 2{{explicitly specialized declaration is here}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif template - struct InnerTemplate : public T { }; // expected-note 2{{explicitly specialized}} \ - // expected-error{{base specifier}} + struct InnerTemplate : public T { }; // expected-note {{explicitly specialized declaration is here}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif + // expected-error@-4 {{base specifier must name a class}} template - void ft1(T t, U u); // expected-note{{explicitly specialized}} + void ft1(T t, U u); +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif }; } @@ -76,7 +104,10 @@ void N0::X0::ft1(T t, U u) { template T N0::X0::member; -template<> struct N0::X0 { }; // expected-warning{{C++11 extension}} +template<> struct N0::X0 { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'X0' outside namespace 'N0' is a C++11 extension}} +#endif N0::X0 test_X0; namespace N1 { @@ -92,7 +123,10 @@ template<> struct N0::X0 { }; // -- member function of a class template -template<> void N0::X0::f1(void *) { } // expected-warning{{member function specialization}} +template<> void N0::X0::f1(void *) { } +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of member function specialization of 'f1' outside namespace 'N0' is a C++11 extension}} +#endif void test_spec(N0::X0 xvp, void *vp) { xvp.f1(vp); @@ -125,7 +159,10 @@ NonDefaultConstructible &get_static_member() { return N0::X0::member; } -template<> int N0::X0::member; // expected-warning{{C++11 extension}} +template<> int N0::X0::member; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of static data member specialization of 'member' outside namespace 'N0' is a C++11 extension}} +#endif template<> float N0::X0::member = 3.14f; @@ -153,7 +190,10 @@ namespace N0 { } template<> -struct N0::X0::Inner { }; // expected-warning{{C++11 extension}} +struct N0::X0::Inner { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of member class specialization of 'Inner' outside namespace 'N0' is a C++11 extension}} +#endif template<> struct N0::X0::Inner { }; @@ -192,7 +232,10 @@ template<> template<> struct N0::X0::InnerTemplate { }; // okay template<> template<> -struct N0::X0::InnerTemplate { }; // expected-warning{{class template specialization}} +struct N0::X0::InnerTemplate { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'InnerTemplate' outside namespace 'N0' is a C++11 extension}} +#endif namespace N1 { template<> template<> @@ -224,7 +267,10 @@ template<> template<> void N0::X0::ft1(void *, unsigned) { } // okay template<> template<> -void N0::X0::ft1(void *, float) { } // expected-warning{{function template specialization}} +void N0::X0::ft1(void *, float) { } +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of function template specialization of 'ft1' outside namespace 'N0' is a C++11 extension}} +#endif namespace N1 { template<> template<> diff --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp index c8b7def..d82691c 100644 --- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp @@ -1,14 +1,20 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace N { - template class X; // expected-note {{'N::X' declared here}} \ - // expected-note {{explicitly specialized declaration is here}} + template class X; // expected-note {{'N::X' declared here}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif } // TODO: Don't add a namespace qualifier to the template if it would trigger // the warning about the specialization being outside of the namespace. -template<> class X { /* ... */ }; // expected-error {{no template named 'X'; did you mean 'N::X'?}} \ - // expected-warning {{first declaration of class template specialization of 'X' outside namespace 'N' is a C++11 extension}} +template<> class X { /* ... */ }; // expected-error {{no template named 'X'; did you mean 'N::X'?}} +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'X' outside namespace 'N' is a C++11 extension}} +#endif namespace N { diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp index 1dfcf0c..0270221 100644 --- a/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=c++98 -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=c++11 %s // Example from the standard template class Array { void mf() { } }; @@ -39,5 +41,16 @@ namespace N { } using namespace N; -template struct X1; // expected-warning{{must occur in}} -template void f1(int); // expected-warning{{must occur in}} +template struct X1; +#if __cplusplus <= 199711L +// expected-warning@-2 {{explicit instantiation of 'N::X1' must occur in namespace 'N'}} +#else +// expected-error@-4 {{explicit instantiation of 'N::X1' must occur in namespace 'N'}} +#endif + +template void f1(int); +#if __cplusplus <= 199711L +// expected-warning@-2 {{explicit instantiation of 'N::f1' must occur in namespace 'N'}} +#else +// expected-error@-4 {{explicit instantiation of 'N::f1' must occur in namespace 'N'}} +#endif diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp index 8422c51..ca1f9a3 100644 --- a/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace N { template class Y { // expected-note{{explicit instantiation refers here}} @@ -11,7 +13,12 @@ template class Z; // expected-error{{explicit instantiation of non-template // FIXME: This example from the standard is wrong; note posted to CWG reflector // on 10/27/2009 using N::Y; -template class Y; // expected-warning{{must occur in}} +template class Y; +#if __cplusplus <= 199711L +// expected-warning@-2 {{explicit instantiation of 'N::Y' must occur in namespace 'N'}} +#else +// expected-error@-4 {{explicit instantiation of 'N::Y' must occur in namespace 'N'}} +#endif template class N::Y; template void N::Y::mf(); diff --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp b/clang/test/CodeGenCXX/debug-info-static-member.cpp index 8e5207d..81ab203 100644 --- a/clang/test/CodeGenCXX/debug-info-static-member.cpp +++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp @@ -1,4 +1,6 @@ // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s +// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S -o - | FileCheck %s +// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s // PR14471 enum X { @@ -10,7 +12,11 @@ class C const static bool const_a = true; protected: static int b; +#if __cplusplus >= 201103L + constexpr static float const_b = 3.14; +#else const static float const_b = 3.14; +#endif public: static int c; const static int const_c = 18; diff --git a/clang/test/SemaCXX/dcl_init_aggr.cpp b/clang/test/SemaCXX/dcl_init_aggr.cpp index 432c116..2b5149c 100644 --- a/clang/test/SemaCXX/dcl_init_aggr.cpp +++ b/clang/test/SemaCXX/dcl_init_aggr.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s +// RUN: %clang_cc1 -fsyntax-only -pedantic -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -pedantic -verify -std=c++11 %s // C++ [dcl.init.aggr]p2 struct A { int x; @@ -9,14 +11,29 @@ struct A { } a1 = { 1, { 2, 3 } }; struct NonAggregate { +#if __cplusplus >= 201103L +// expected-note@-2 3 {{candidate constructor (the implicit copy constructor) not viable}} +// expected-note@-3 3 {{candidate constructor (the implicit move constructor) not viable}} +#endif NonAggregate(); - +#if __cplusplus >= 201103L +// expected-note@-2 3 {{candidate constructor not viable: requires 0 arguments, but 2 were provided}} +#endif int a, b; }; -NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{non-aggregate type 'NonAggregate' cannot be initialized with an initializer list}} - -NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; // expected-error 2 {{non-aggregate type 'NonAggregate' cannot be initialized with an initializer list}} - +NonAggregate non_aggregate_test = { 1, 2 }; +#if __cplusplus <= 199711L +// expected-error@-2 {{non-aggregate type 'NonAggregate' cannot be initialized with an initializer list}} +#else +// expected-error@-4 {{no matching constructor for initialization of 'NonAggregate'}} +#endif + +NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; +#if __cplusplus <= 199711L +// expected-error@-2 2 {{non-aggregate type 'NonAggregate' cannot be initialized with an initializer list}} +#else +// expected-error@-4 2 {{no matching constructor for initialization of 'NonAggregate'}} +#endif // C++ [dcl.init.aggr]p3 A a_init = A(); @@ -38,20 +55,55 @@ char cv[4] = { 'a', 's', 'd', 'f', 0 }; // expected-error{{excess elements in ar // C++ [dcl.init.aggr]p7 struct TooFew { int a; char* b; int c; }; -TooFew too_few = { 1, "asdf" }; // expected-warning{{conversion from string literal to 'char *' is deprecated}} +TooFew too_few = { 1, "asdf" }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} +#else +// expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}} +#endif + +struct NoDefaultConstructor { +#if __cplusplus <= 199711L +// expected-note@-2 3 {{candidate constructor (the implicit copy constructor)}} +// expected-note@-3 {{declared here}} +#else +// expected-note@-5 4 {{candidate constructor (the implicit copy constructor)}} +// expected-note@-6 4 {{candidate constructor (the implicit move constructor)}} +#endif + + NoDefaultConstructor(int); +#if __cplusplus <= 199711L + // expected-note@-2 3 {{candidate constructor not viable: requires 1 argument, but 0 were provided}} +#else + // expected-note@-4 4 {{candidate constructor not viable: requires 1 argument, but 0 were provided}} +#endif -struct NoDefaultConstructor { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} \ - // expected-note{{declared here}} - NoDefaultConstructor(int); // expected-note 3 {{candidate constructor}} }; -struct TooFewError { // expected-error{{implicit default constructor for}} +struct TooFewError { +#if __cplusplus <= 199711L +// expected-error@-2 {{implicit default constructor for}} +#endif + int a; - NoDefaultConstructor nodef; // expected-note{{member is declared here}} expected-note 2{{in implicit initialization of field 'nodef'}} + NoDefaultConstructor nodef; +#if __cplusplus <= 199711L +// expected-note@-2 {{member is declared here}} +// expected-note@-3 2{{in implicit initialization of field 'nodef' with omitted initializer}} +#else +// expected-note@-5 3{{in implicit initialization of field 'nodef' with omitted initializer}} +#endif }; TooFewError too_few_okay = { 1, 1 }; TooFewError too_few_error = { 1 }; // expected-error{{no matching constructor}} -TooFewError too_few_okay2[2] = { 1, 1 }; // expected-note{{implicit default constructor for 'TooFewError' first required here}} +TooFewError too_few_okay2[2] = { 1, 1 }; +#if __cplusplus <= 199711L +// expected-note@-2 {{implicit default constructor for 'TooFewError' first required here}} +#else +// expected-error@-4 {{no matching constructor for initialization of 'NoDefaultConstructor'}} +// expected-note@-5 {{in implicit initialization of array element 1 with omitted initializer}} +#endif + TooFewError too_few_error2[2] = { 1 }; // expected-error{{no matching constructor}} NoDefaultConstructor too_few_error3[3] = { }; // expected-error {{no matching constructor}} expected-note {{implicit initialization of array element 0}} @@ -116,6 +168,10 @@ B2 b2_3 = { c2, a2, a2 }; // C++ [dcl.init.aggr]p15: union u { int a; char* b; }; // expected-note{{candidate constructor (the implicit copy constructor)}} +#if __cplusplus >= 201103L +// expected-note@-2 {{candidate constructor (the implicit move constructor)}} +#endif + u u1 = { 1 }; u u2 = u1; u u3 = 1; // expected-error{{no viable conversion}} diff --git a/clang/test/SemaCXX/type-convert-construct.cpp b/clang/test/SemaCXX/type-convert-construct.cpp index 2dec50a..7ae8363 100644 --- a/clang/test/SemaCXX/type-convert-construct.cpp +++ b/clang/test/SemaCXX/type-convert-construct.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s void f() { float v1 = float(1); @@ -12,8 +14,21 @@ void f() { typedef int T; int *p; bool v6 = T(0) == p; +#if __cplusplus >= 201103L + // expected-error@-2 {{comparison between pointer and integer ('T' (aka 'int') and 'int *')}} +#endif char *str; - str = "a string"; // expected-warning{{conversion from string literal to 'char *' is deprecated}} + str = "a string"; +#if __cplusplus <= 199711L + // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} +#else + // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}} +#endif wchar_t *wstr; - wstr = L"a wide string"; // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}} + wstr = L"a wide string"; +#if __cplusplus <= 199711L + // expected-warning@-2 {{conversion from string literal to 'wchar_t *' is deprecated}} +#else + // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'wchar_t *'}} +#endif } diff --git a/clang/test/SemaCXX/vararg-non-pod.cpp b/clang/test/SemaCXX/vararg-non-pod.cpp index 39d4ccc..1b7f3b6 100644 --- a/clang/test/SemaCXX/vararg-non-pod.cpp +++ b/clang/test/SemaCXX/vararg-non-pod.cpp @@ -1,7 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++98 %s -Wno-error=non-pod-varargs +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s -Wno-error=non-pod-varargs // Check that the warning is still there under -fms-compatibility. // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs -fms-compatibility +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++98 %s -Wno-error=non-pod-varargs -fms-compatibility +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s -Wno-error=non-pod-varargs -fms-compatibility extern char version[]; @@ -18,11 +22,19 @@ void t1() { C c(10); - g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} + g(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} +#endif + g(10, version); void (*ptr)(int, ...) = g; - ptr(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} + ptr(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} +#endif + ptr(10, version); } @@ -30,18 +42,34 @@ void t2() { C c(10); - c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} + c.g(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} +#endif + c.g(10, version); void (C::*ptr)(int, ...) = &C::g; - (c.*ptr)(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} + (c.*ptr)(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} +#endif + (c.*ptr)(10, version); - C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} + C::h(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} +#endif + C::h(10, version); void (*static_ptr)(int, ...) = &C::h; - static_ptr(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} + static_ptr(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} +#endif + static_ptr(10, version); } @@ -51,7 +79,11 @@ void t3() { C c(10); - block(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} + block(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} +#endif + block(10, version); } @@ -66,7 +98,11 @@ void t4() D d; - d(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} + d(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} +#endif + d(10, version); } @@ -78,10 +114,16 @@ void t5() { C c(10); - E e(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \ - // expected-error{{calling a private constructor of class 'E'}} - (void)E(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \ - // expected-error{{calling a private constructor of class 'E'}} + E e(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} +#endif + // expected-error@-4 {{calling a private constructor of class 'E'}} + (void)E(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} +#endif + // expected-error@-4 {{calling a private constructor of class 'E'}} } @@ -103,7 +145,13 @@ Base &get_base(...); int eat_base(...); void test_typeid(Base &base) { - (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} expected-warning{{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} + (void)typeid(get_base(base)); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} +#else + // expected-warning@-4 {{cannot pass object of non-trivial type 'Base' through variadic function; call will abort at runtime}} +#endif + // expected-warning@-6 {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} (void)typeid(eat_base(base)); // okay } @@ -136,7 +184,10 @@ void t8(int n, ...) { int t9(int n) { // Make sure the error works in potentially-evaluated sizeof - return (int)sizeof(*(Helper(Foo()), (int (*)[n])0)); // expected-warning{{cannot pass object of non-POD type}} + return (int)sizeof(*(Helper(Foo()), (int (*)[n])0)); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'Foo' through variadic function; call will abort at runtime}} +#endif } // PR14057 @@ -173,22 +224,43 @@ namespace t11 { void test() { C c(10); - (get_f_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} + (get_f_ptr())(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} +#endif (get_f_ptr())(10, version); - (c.*get_m_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} + (c.*get_m_ptr())(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} +#endif (c.*get_m_ptr())(10, version); - (get_b_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} + (get_b_ptr())(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} +#endif + (get_b_ptr())(10, version); - (arr_f_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} + (arr_f_ptr[3])(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} +#endif + (arr_f_ptr[3])(10, version); - (c.*arr_m_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} + (c.*arr_m_ptr[3])(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} +#endif + (c.*arr_m_ptr[3])(10, version); - (arr_b_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} + (arr_b_ptr[3])(10, c); +#if __cplusplus <= 199711L + // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} +#endif (arr_b_ptr[3])(10, version); } } diff --git a/clang/test/SemaTemplate/class-template-spec.cpp b/clang/test/SemaTemplate/class-template-spec.cpp index 0292c1b..86cace1 100644 --- a/clang/test/SemaTemplate/class-template-spec.cpp +++ b/clang/test/SemaTemplate/class-template-spec.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template struct A; // expected-note {{template is declared here}} \ // expected-note{{explicitly specialized}} @@ -75,7 +77,10 @@ struct A { }; // expected-error{{template specialization requires 'templ template<> struct ::A; namespace N { - template struct B; // expected-note 2{{explicitly specialized}} + template struct B; // expected-note {{explicitly specialized}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized}} +#endif template<> struct ::N::B; // okay template<> struct ::N::B; // okay @@ -86,7 +91,11 @@ namespace N { template<> struct N::B { }; // okay -template<> struct N::B { }; // expected-warning{{C++11 extension}} +template<> struct N::B { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'B' outside namespace 'N' is a C++11 extension}} +#endif + namespace M { template<> struct ::N::B { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} @@ -142,13 +151,26 @@ namespace PR18009 { } namespace PR16519 { - template struct integer_sequence { typedef T value_type; }; // expected-warning {{extension}} + template struct integer_sequence { typedef T value_type; }; +#if __cplusplus <= 199711L + // expected-warning@-2 {{variadic templates are a C++11 extension}} +#endif template struct __make_integer_sequence; - template using make_integer_sequence = typename __make_integer_sequence::template make::type; // expected-warning {{extension}} - - template struct __make_integer_sequence_impl; // expected-warning {{extension}} - template struct __make_integer_sequence_impl, Extra...> { // expected-warning 2{{extension}} + template using make_integer_sequence = typename __make_integer_sequence::template make::type; +#if __cplusplus <= 199711L + // expected-warning@-2 {{alias declarations are a C++11 extension}} +#endif + + template struct __make_integer_sequence_impl; +#if __cplusplus <= 199711L + // expected-warning@-2 {{variadic templates are a C++11 extension}} +#endif + + template struct __make_integer_sequence_impl, Extra...> { +#if __cplusplus <= 199711L + // expected-warning@-2 2 {{variadic templates are a C++11 extension}} +#endif typedef integer_sequence type; }; @@ -160,8 +182,15 @@ namespace PR16519 { template struct make : __make_integer_sequence_impl, N - 1> {}; }; - using X = make_integer_sequence; // expected-warning {{extension}} - using X = integer_sequence; // expected-warning {{extension}} + using X = make_integer_sequence; +#if __cplusplus <= 199711L + // expected-warning@-2 {{alias declarations are a C++11 extension}} +#endif + + using X = integer_sequence; +#if __cplusplus <= 199711L + // expected-warning@-2 {{alias declarations are a C++11 extension}} +#endif } namespace DefaultArgVsPartialSpec { diff --git a/clang/test/SemaTemplate/instantiate-cast.cpp b/clang/test/SemaTemplate/instantiate-cast.cpp index b3babf1..32a1cfd 100644 --- a/clang/test/SemaTemplate/instantiate-cast.cpp +++ b/clang/test/SemaTemplate/instantiate-cast.cpp @@ -1,6 +1,13 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s - -struct A { int x; }; // expected-note 2 {{candidate constructor}} +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct A { int x; }; +// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument}} +#if __cplusplus >= 201103L +// expected-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A' for 1st argument}} +#endif +// expected-note@-5 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}} class Base { public: diff --git a/clang/test/SemaTemplate/instantiate-expr-4.cpp b/clang/test/SemaTemplate/instantiate-expr-4.cpp index d95ccfe..9a1a1d2 100644 --- a/clang/test/SemaTemplate/instantiate-expr-4.cpp +++ b/clang/test/SemaTemplate/instantiate-expr-4.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s // --------------------------------------------------------------------- // C++ Functional Casts @@ -22,6 +24,9 @@ struct FunctionalCast0 { template struct FunctionalCast0<5>; struct X { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} +#if __cplusplus >= 201103L +// expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}} +#endif X(int, int); // expected-note 3 {{candidate constructor}} }; @@ -213,6 +218,10 @@ template struct InitList1 { void f(Val1 val1) { T x = { val1 }; +#if __cplusplus >= 201103L + // expected-error@-2 {{type 'float' cannot be narrowed to 'int' in initializer list}} + // expected-note@-3 {{insert an explicit cast to silence this issue}} +#endif } }; @@ -222,6 +231,9 @@ struct APair { }; template struct InitList1; +#if __cplusplus >= 201103L +// expected-note@-2 {{instantiation of member function}} +#endif template struct InitList1; template diff --git a/clang/test/SemaTemplate/instantiate-member-class.cpp b/clang/test/SemaTemplate/instantiate-member-class.cpp index 3f49606..159bccb 100644 --- a/clang/test/SemaTemplate/instantiate-member-class.cpp +++ b/clang/test/SemaTemplate/instantiate-member-class.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace PR8965 { template @@ -106,7 +108,10 @@ namespace test2 { namespace AliasTagDef { template struct F { - using S = struct U { // expected-warning {{C++11}} + using S = struct U { +#if __cplusplus <= 199711L + // expected-warning@-2 {{alias declarations are a C++11 extension}} +#endif T g() { return T(); } @@ -122,8 +127,13 @@ namespace rdar10397846 { { struct B { - struct C { C() { int *ptr = I; } }; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \ - expected-warning{{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} + struct C { C() { int *ptr = I; } }; +#if __cplusplus >= 201103L + // expected-error@-2 {{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} +#else + // expected-warning@-4 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} +#endif + // expected-error@-6 {{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} }; }; -- 2.7.4