Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Lit C++11 Compatibility Patch #8
Browse files Browse the repository at this point in the history
24 tests have been updated for C++11 compatibility.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266387 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Charles Li committed Apr 14, 2016
1 parent d077ad4 commit 234233d
Show file tree
Hide file tree
Showing 24 changed files with 529 additions and 92 deletions.
17 changes: 14 additions & 3 deletions test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify -std=c++11 %s

// C++98 [basic.lookup.classref]p1:
// In a class member access expression (5.2.5), if the . or -> token is
Expand All @@ -21,10 +23,16 @@

// From PR 7247
template<typename T>
struct set{}; // expected-note{{lookup from the current scope refers here}}
struct set{};
#if __cplusplus <= 199711L
// expected-note@-2 {{lookup from the current scope refers here}}
#endif
struct Value {
template<typename T>
void set(T value) {} // expected-note{{lookup in the object type 'Value' refers here}}
void set(T value) {}
#if __cplusplus <= 199711L
// expected-note@-2 {{lookup in the object type 'Value' refers here}}
#endif

void resolves_to_same() {
Value v;
Expand All @@ -36,7 +44,10 @@ void resolves_to_different() {
Value v;
// The fact that the next line is a warning rather than an error is an
// extension.
v.set<double>(3.2); // expected-warning{{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
v.set<double>(3.2);
#if __cplusplus <= 199711L
// expected-warning@-2 {{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
#endif
}
{
int set; // Non-template.
Expand Down
7 changes: 6 additions & 1 deletion test/CXX/class/class.friend/p1.cpp
Original file line number Diff line number Diff line change
@@ -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

struct Outer {
struct Inner {
Expand Down Expand Up @@ -41,7 +43,10 @@ class A {
UndeclaredSoFar x; // expected-error {{unknown type name 'UndeclaredSoFar'}}

void a_member();
friend void A::a_member(); // expected-error {{friends cannot be members of the declaring class}}
friend void A::a_member();
#if __cplusplus <= 199711L
// expected-error@-2 {{friends cannot be members of the declaring class}}
#endif
friend void a_member(); // okay (because we ignore class scopes when looking up friends)
friend class A::AInner; // this is okay as an extension
friend class AInner; // okay, refers to ::AInner
Expand Down
12 changes: 10 additions & 2 deletions test/CXX/class/class.friend/p2.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// 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 B0;

class A {
friend class B {}; // expected-error {{cannot define a type in a friend declaration}}
friend int; // expected-warning {{non-class friend type 'int' is a C++11 extension}}
friend B0; // expected-warning {{specify 'struct' to befriend 'B0'}}
friend int;
#if __cplusplus <= 199711L
// expected-warning@-2 {{non-class friend type 'int' is a C++11 extension}}
#endif
friend B0;
#if __cplusplus <= 199711L
// expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'struct' to befriend 'B0'}}
#endif
friend class C; // okay
};
14 changes: 12 additions & 2 deletions test/CXX/stmt.stmt/stmt.dcl/p3.cpp
Original file line number Diff line number Diff line change
@@ -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

// PR10034
struct X {};
Expand Down Expand Up @@ -40,8 +42,16 @@ struct Z {
};

void test_Z() {
goto end; // expected-error{{cannot jump from this goto statement to its label}}
Z z; // expected-note{{jump bypasses initialization of non-POD variable}}
goto end;
#if __cplusplus <= 199711L
// expected-error@-2 {{cannot jump from this goto statement to its label}}
#endif

Z z;
#if __cplusplus <= 199711L
// expected-note@-2 {{jump bypasses initialization of non-POD variable}}
#endif

end:
return;
}
128 changes: 110 additions & 18 deletions test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-linux-gnu %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-linux-gnu -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-linux-gnu -std=c++11 %s
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64-linux-gnu %s -DCPP11ONLY

// C++11 [temp.arg.nontype]p1:
Expand Down Expand Up @@ -31,55 +33,135 @@ namespace non_type_tmpl_param {
// if the corresopnding template-parameter is a reference; or
namespace addr_of_obj_or_func {
template <int* p> struct X0 { }; // expected-note 5{{here}}
#if __cplusplus >= 201103L
// expected-note@-2 2{{template parameter is declared here}}
#endif

template <int (*fp)(int)> struct X1 { };
template <int &p> struct X2 { }; // expected-note 4{{here}}
template <const int &p> struct X2k { }; // expected-note {{here}}
template <int (&fp)(int)> struct X3 { }; // expected-note 4{{here}}

int i = 42;
#if __cplusplus >= 201103L
// expected-note@-2 {{declared here}}
#endif

int iarr[10];
int f(int i);
const int ki = 9; // expected-note 5{{here}}
__thread int ti = 100; // expected-note 2{{here}}
static int f_internal(int); // expected-note 4{{here}}
const int ki = 9;
#if __cplusplus <= 199711L
// expected-note@-2 5{{non-type template argument refers to object here}}
#endif

__thread int ti = 100; // expected-note {{here}}
#if __cplusplus <= 199711L
// expected-note@-2 {{here}}
#endif

static int f_internal(int);
#if __cplusplus <= 199711L
// expected-note@-2 4{{non-type template argument refers to function here}}
#endif

template <typename T> T f_tmpl(T t);
struct S { union { int NonStaticMember; }; };

void test() {
X0<i> x0a; // expected-error {{must have its address taken}}
X0<i> x0a;
#if __cplusplus <= 199711L
// expected-error@-2 {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
#else
// expected-error@-4 {{non-type template argument of type 'int' is not a constant expression}}
// expected-note@-5 {{read of non-const variable 'i' is not allowed in a constant expression}}
#endif
X0<&i> x0a_addr;
X0<iarr> x0b;
X0<&iarr> x0b_addr; // expected-error {{cannot be converted to a value of type 'int *'}}
X0<ki> x0c; // expected-error {{must have its address taken}} expected-warning {{internal linkage is a C++11 extension}}
X0<&ki> x0c_addr; // expected-error {{cannot be converted to a value of type 'int *'}} expected-warning {{internal linkage is a C++11 extension}}
X0<&ti> x0d_addr; // expected-error {{refers to thread-local object}}
X0<ki> x0c; // expected-error {{must have its address taken}}
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X0<&ki> x0c_addr; // expected-error {{cannot be converted to a value of type 'int *'}}
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X0<&ti> x0d_addr;
#if __cplusplus <= 199711L
// expected-error@-2 {{non-type template argument refers to thread-local object}}
#else
// expected-error@-4 {{non-type template argument of type 'int *' is not a constant expression}}
#endif

X1<f> x1a;
X1<&f> x1a_addr;
X1<f_tmpl> x1b;
X1<&f_tmpl> x1b_addr;
X1<f_tmpl<int> > x1c;
X1<&f_tmpl<int> > x1c_addr;
X1<f_internal> x1d; // expected-warning {{internal linkage is a C++11 extension}}
X1<&f_internal> x1d_addr; // expected-warning {{internal linkage is a C++11 extension}}
X1<f_internal> x1d;
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X1<&f_internal> x1d_addr;
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X2<i> x2a;
X2<&i> x2a_addr; // expected-error {{address taken}}
X2<iarr> x2b; // expected-error {{cannot bind to template argument of type 'int [10]'}}
X2<&iarr> x2b_addr; // expected-error {{address taken}}
X2<ki> x2c; // expected-error {{ignores qualifiers}} expected-warning {{internal linkage is a C++11 extension}}
X2k<ki> x2kc; // expected-warning {{internal linkage is a C++11 extension}}
X2k<&ki> x2kc_addr; // expected-error {{address taken}} expected-warning {{internal linkage is a C++11 extension}}
X2<ki> x2c; // expected-error {{ignores qualifiers}}
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X2k<ki> x2kc;
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X2k<&ki> x2kc_addr; // expected-error {{address taken}}
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X2<ti> x2d_addr; // expected-error {{refers to thread-local object}}
X3<f> x3a;
X3<&f> x3a_addr; // expected-error {{address taken}}
X3<f_tmpl> x3b;
X3<&f_tmpl> x3b_addr; // expected-error {{address taken}}
X3<f_tmpl<int> > x3c;
X3<&f_tmpl<int> > x3c_addr; // expected-error {{address taken}}
X3<f_internal> x3d; // expected-warning {{internal linkage is a C++11 extension}}
X3<&f_internal> x3d_addr; // expected-error {{address taken}} expected-warning {{internal linkage is a C++11 extension}}
X3<f_internal> x3d;
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

X3<&f_internal> x3d_addr; // expected-error {{address taken}}
#if __cplusplus <= 199711L
// expected-warning@-2 {{internal linkage is a C++11 extension}}
#endif

int n;
#if __cplusplus <= 199711L
// expected-note@-2 {{non-type template argument refers to object here}}
#else
// expected-note@-4 {{declared here}}
#endif

X0<&n> x0_no_linkage;
#if __cplusplus <= 199711L
// expected-error@-2 {{non-type template argument refers to object 'n' that does not have linkage}}
#else
// expected-error@-4 {{non-type template argument of type 'int *' is not a constant expression}}
// expected-note@-5 {{pointer to 'n' is not a constant expression}}
#endif

int n; // expected-note {{here}}
X0<&n> x0_no_linkage; // expected-error {{non-type template argument refers to object 'n' that does not have linkage}}
struct Local { static int f() {} }; // expected-note {{here}}
X1<&Local::f> x1_no_linkage; // expected-error {{non-type template argument refers to function 'f' that does not have linkage}}
X0<&S::NonStaticMember> x0_non_static; // expected-error {{non-static data member}}
Expand All @@ -96,7 +178,17 @@ namespace bad_args {
int i = 42;
X0<&i + 2> x0a; // expected-error{{non-type template argument does not refer to any declaration}}
int* iptr = &i;
X0<iptr> x0b; // expected-error{{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
#if __cplusplus >= 201103L
// expected-note@-2 {{declared here}}
#endif

X0<iptr> x0b;
#if __cplusplus <= 199711L
// expected-error@-2 {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
#else
// expected-error@-4 {{non-type template argument of type 'int *' is not a constant expression}}
// expected-note@-5 {{read of non-constexpr variable 'iptr' is not allowed in a constant expression}}
#endif
}
#endif // CPP11ONLY

Expand All @@ -108,4 +200,4 @@ int f();
}
#endif // CPP11ONLY

}
}
60 changes: 50 additions & 10 deletions test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
Original file line number Diff line number Diff line change
@@ -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

template<class T> struct A {
static T t; // expected-error{{static data member instantiated with function type 'int ()'}}
};
Expand All @@ -11,10 +14,17 @@ template<typename T> struct B {
B<function> b; // expected-note{{instantiation of}}

template <typename T> int f0(void *, const T&); // expected-note{{candidate template ignored: substitution failure}}
enum {e}; // expected-note{{unnamed type used in template argument was declared here}}
enum {e};
#if __cplusplus <= 199711L
// expected-note@-2 {{unnamed type used in template argument was declared here}}
#endif

void test_f0(int n) {
int i = f0(0, e); // expected-warning{{template argument uses unnamed type}}
int i = f0(0, e);
#if __cplusplus <= 199711L
// expected-warning@-2 {{template argument uses unnamed type}}
#endif

int vla[n];
f0(0, vla); // expected-error{{no matching function for call to 'f0'}}
}
Expand All @@ -23,20 +33,50 @@ namespace N0 {
template <typename R, typename A1> void f0(R (*)(A1));
template <typename T> int f1(T);
template <typename T, typename U> int f1(T, U);
enum {e1}; // expected-note 2{{unnamed type used in template argument was declared here}}
enum {e2}; // expected-note 2{{unnamed type used in template argument was declared here}}
enum {e3}; // expected-note{{unnamed type used in template argument was declared here}}
enum {e1};
#if __cplusplus <= 199711L
// expected-note@-2 2{{unnamed type used in template argument was declared here}}
#endif

enum {e2};
#if __cplusplus <= 199711L
// expected-note@-2 2{{unnamed type used in template argument was declared here}}
#endif

enum {e3};
#if __cplusplus <= 199711L
// expected-note@-2 {{unnamed type used in template argument was declared here}}
#endif

template<typename T> struct X;
template<typename T> struct X<T*> { };

void f() {
f0( // expected-warning{{template argument uses unnamed type}}
&f1<__typeof__(e1)>); // expected-warning{{template argument uses unnamed type}}
int (*fp1)(int, __typeof__(e2)) = f1; // expected-warning{{template argument uses unnamed type}}
f1(e2); // expected-warning{{template argument uses unnamed type}}
f0(
#if __cplusplus <= 199711L
// expected-warning@-2 {{template argument uses unnamed type}}
#endif

&f1<__typeof__(e1)>);
#if __cplusplus <= 199711L
// expected-warning@-2 {{template argument uses unnamed type}}
#endif

int (*fp1)(int, __typeof__(e2)) = f1;
#if __cplusplus <= 199711L
// expected-warning@-2 {{template argument uses unnamed type}}
#endif

f1(e2);
#if __cplusplus <= 199711L
// expected-warning@-2 {{template argument uses unnamed type}}
#endif

f1(e2);

X<__typeof__(e3)*> x; // expected-warning{{template argument uses unnamed type}}
X<__typeof__(e3)*> x;
#if __cplusplus <= 199711L
// expected-warning@-2 {{template argument uses unnamed type}}
#endif
}
}
Loading

0 comments on commit 234233d

Please sign in to comment.