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
This commit is contained in:
Charles Li 2016-04-13 20:00:45 +00:00
parent c0bef99bb0
commit 64a1a81e76
13 changed files with 523 additions and 93 deletions

View File

@ -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 <class T> 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 <class T> struct B : A<T> {
A<T>::type; // expected-error {{dependent using declaration resolved to type without 'typename'}} // expected-warning {{access declarations are deprecated}}
A<T>::hiding; // expected-warning {{access declarations are deprecated}}
A<T>::union_member; // expected-warning {{access declarations are deprecated}}
A<T>::enumerator; // expected-warning {{access declarations are deprecated}}
A<T>::tagname; // expected-error {{dependent using declaration resolved to type without 'typename'}} // expected-warning {{access declarations are deprecated}}
A<T>::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<T>::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<T>::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<T>::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<T>::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 <class T> 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}}
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
int bar(); //expected-note {{target of using declaration}}
C::bar; // expected-error {{refers to its own class}} expected-warning {{access declarations are deprecated}}
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}}
};
}

View File

@ -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<typename T> void f0(T) { // expected-note{{here}}
template<typename T> 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<typename T>
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<typename U>
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<typename U>
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<T>::ft1(T t, U u) {
template<typename T> T N0::X0<T>::member;
template<> struct N0::X0<void> { }; // expected-warning{{C++11 extension}}
template<> struct N0::X0<void> { };
#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<void> test_X0;
namespace N1 {
@ -92,7 +123,10 @@ template<> struct N0::X0<volatile void> {
};
// -- member function of a class template
template<> void N0::X0<void*>::f1(void *) { } // expected-warning{{member function specialization}}
template<> void N0::X0<void*>::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<void*> xvp, void *vp) {
xvp.f1(vp);
@ -125,7 +159,10 @@ NonDefaultConstructible &get_static_member() {
return N0::X0<NonDefaultConstructible>::member;
}
template<> int N0::X0<int>::member; // expected-warning{{C++11 extension}}
template<> int N0::X0<int>::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<float>::member = 3.14f;
@ -153,7 +190,10 @@ namespace N0 {
}
template<>
struct N0::X0<long>::Inner { }; // expected-warning{{C++11 extension}}
struct N0::X0<long>::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<float>::Inner { };
@ -192,7 +232,10 @@ template<> template<>
struct N0::X0<int>::InnerTemplate<long> { }; // okay
template<> template<>
struct N0::X0<int>::InnerTemplate<float> { }; // expected-warning{{class template specialization}}
struct N0::X0<int>::InnerTemplate<float> { };
#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<void*>::ft1(void *, unsigned) { } // okay
template<> template<>
void N0::X0<void*>::ft1(void *, float) { } // expected-warning{{function template specialization}}
void N0::X0<void*>::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<>

View File

@ -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 T> class X; // expected-note {{'N::X' declared here}} \
// expected-note {{explicitly specialized declaration is here}}
template<class T> 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<int> { /* ... */ }; // 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<int> { /* ... */ }; // 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 {

View File

@ -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 T> class Array { void mf() { } };
@ -39,5 +41,16 @@ namespace N {
}
using namespace N;
template struct X1<int>; // expected-warning{{must occur in}}
template void f1(int); // expected-warning{{must occur in}}
template struct X1<int>;
#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

View File

@ -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 T> class Y { // expected-note{{explicit instantiation refers here}}
@ -11,7 +13,12 @@ template class Z<int>; // 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<int>; // expected-warning{{must occur in}}
template class Y<int>;
#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<char*>;
template void N::Y<double>::mf();

View File

@ -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;

View File

@ -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}}

View File

@ -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
}

View File

@ -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);
}
}

View File

@ -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<typename T, typename U = int> struct A; // expected-note {{template is declared here}} \
// expected-note{{explicitly specialized}}
@ -75,7 +77,10 @@ struct A<double> { }; // expected-error{{template specialization requires 'templ
template<> struct ::A<double>;
namespace N {
template<typename T> struct B; // expected-note 2{{explicitly specialized}}
template<typename T> struct B; // expected-note {{explicitly specialized}}
#if __cplusplus <= 199711L
// expected-note@-2 {{explicitly specialized}}
#endif
template<> struct ::N::B<char>; // okay
template<> struct ::N::B<short>; // okay
@ -86,7 +91,11 @@ namespace N {
template<> struct N::B<int> { }; // okay
template<> struct N::B<float> { }; // expected-warning{{C++11 extension}}
template<> struct N::B<float> { };
#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<short> { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}}
@ -142,13 +151,26 @@ namespace PR18009 {
}
namespace PR16519 {
template<typename T, T...N> struct integer_sequence { typedef T value_type; }; // expected-warning {{extension}}
template<typename T, T...N> struct integer_sequence { typedef T value_type; };
#if __cplusplus <= 199711L
// expected-warning@-2 {{variadic templates are a C++11 extension}}
#endif
template<typename T> struct __make_integer_sequence;
template<typename T, T N> using make_integer_sequence = typename __make_integer_sequence<T>::template make<N, N % 2>::type; // expected-warning {{extension}}
template<typename T, T N> using make_integer_sequence = typename __make_integer_sequence<T>::template make<N, N % 2>::type;
#if __cplusplus <= 199711L
// expected-warning@-2 {{alias declarations are a C++11 extension}}
#endif
template<typename T, typename T::value_type ...Extra> struct __make_integer_sequence_impl; // expected-warning {{extension}}
template<typename T, T ...N, T ...Extra> struct __make_integer_sequence_impl<integer_sequence<T, N...>, Extra...> { // expected-warning 2{{extension}}
template<typename T, typename T::value_type ...Extra> struct __make_integer_sequence_impl;
#if __cplusplus <= 199711L
// expected-warning@-2 {{variadic templates are a C++11 extension}}
#endif
template<typename T, T ...N, T ...Extra> struct __make_integer_sequence_impl<integer_sequence<T, N...>, Extra...> {
#if __cplusplus <= 199711L
// expected-warning@-2 2 {{variadic templates are a C++11 extension}}
#endif
typedef integer_sequence<T, N..., sizeof...(N) + N..., Extra...> type;
};
@ -160,8 +182,15 @@ namespace PR16519 {
template<T N, typename Dummy> struct make<N, 1, Dummy> : __make_integer_sequence_impl<make_integer_sequence<T, N/2>, N - 1> {};
};
using X = make_integer_sequence<int, 5>; // expected-warning {{extension}}
using X = integer_sequence<int, 0, 1, 2, 3, 4>; // expected-warning {{extension}}
using X = make_integer_sequence<int, 5>;
#if __cplusplus <= 199711L
// expected-warning@-2 {{alias declarations are a C++11 extension}}
#endif
using X = integer_sequence<int, 0, 1, 2, 3, 4>;
#if __cplusplus <= 199711L
// expected-warning@-2 {{alias declarations are a C++11 extension}}
#endif
}
namespace DefaultArgVsPartialSpec {

View File

@ -1,6 +1,13 @@
// 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
struct A { int x; }; // expected-note 2 {{candidate constructor}}
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:

View File

@ -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<typename T, typename Val1>
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<int[1], float>;
#if __cplusplus >= 201103L
// expected-note@-2 {{instantiation of member function}}
#endif
template struct InitList1<APair, int*>;
template<typename T, typename Val1, typename Val2>

View File

@ -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<typename T>
@ -106,7 +108,10 @@ namespace test2 {
namespace AliasTagDef {
template<typename T>
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'}}
};
};