Skip to content

Commit

Permalink
[Test] Make Lit tests C++11 compatible #10
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D21626

llvm-svn: 296193
  • Loading branch information
Charles Li committed Feb 24, 2017
1 parent d934cb8 commit 6de8aca
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 44 deletions.
6 changes: 6 additions & 0 deletions clang/test/Modules/Inputs/merge-using-decls/b.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ template<typename T> struct D : X, T {
using typename X::t;
};

#if __cplusplus <= 199711L // C++11 does not allow access declerations
template<typename T> struct E : X, T {
// Mismatch in using/access-declaration-ness.
T::value;
X::v;
};
#endif

template<typename T> struct F : X, T {
// Mismatch in nested-name-specifier.
Expand All @@ -46,5 +48,9 @@ template<typename T> struct F : X, T {
// Force instantiation.
typedef C<YB>::type I;
typedef D<YBRev>::t I;

#if __cplusplus <= 199711L // C++11 does not allow access declerations
typedef E<YB>::type I;
#endif

typedef F<YB>::type I;
13 changes: 13 additions & 0 deletions clang/test/Modules/merge-using-decls.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=1
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=1
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=1
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=2
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=2
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2

#if ORDER == 1
#include "a.h"
Expand All @@ -24,7 +28,11 @@ template<typename T> int Use() {
}

template<typename T> int UseAll() {
#if __cplusplus <= 199711L // C++11 does not allow access declerations
return Use<C<T> >() + Use<D<T> >() + Use<E<T> >() + Use<F<T> >(); // expected-note 0-2{{instantiation of}}
#else
return Use<C<T> >() + Use<D<T> >() + Use<F<T> >(); // expected-note 0-2{{instantiation of}}
#endif
}

template int UseAll<YA>();
Expand All @@ -37,8 +45,10 @@ template int UseAll<Y>();
// Here, we're instantiating the definition from 'A' and merging the definition
// from 'B' into it.

#if __cplusplus <= 199711L // C++11 does not allow access declerations
// expected-error@b.h:* {{'E::value' from module 'B' is not present in definition of 'E<T>' in module 'A'}}
// expected-error@b.h:* {{'E::v' from module 'B' is not present in definition of 'E<T>' in module 'A'}}
#endif

// expected-error@b.h:* {{'F::type' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
// expected-error@b.h:* {{'F::t' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
Expand All @@ -55,11 +65,14 @@ template int UseAll<Y>();
// expected-error@b.h:* 2{{'typename' keyword used on a non-type}}
// expected-error@b.h:* 2{{dependent using declaration resolved to type without 'typename'}}

#if __cplusplus <= 199711L // C++11 does not allow access declerations
// expected-error@a.h:* {{'E::type' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
// expected-error@a.h:* {{'E::t' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
// expected-error@a.h:* {{'E::value' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
// expected-error@a.h:* {{'E::v' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
// expected-note@b.h:* 2{{definition has no member}}
#endif


// expected-error@a.h:* {{'F::type' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
// expected-error@a.h:* {{'F::t' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
Expand Down
43 changes: 39 additions & 4 deletions clang/test/SemaCXX/PR9572.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
// 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

class Base {
virtual ~Base(); // expected-note {{implicitly declared private here}}
virtual ~Base();
#if __cplusplus <= 199711L
// expected-note@-2 {{implicitly declared private here}}
#else
// expected-note@-4 {{overridden virtual function is here}}
#endif
};
struct Foo : public Base { // expected-error {{base class 'Base' has private destructor}}
const int kBlah = 3; // expected-warning {{is a C++11 extension}}

struct Foo : public Base {
#if __cplusplus <= 199711L
// expected-error@-2 {{base class 'Base' has private destructor}}
#else
// expected-error@-4 {{deleted function '~Foo' cannot override a non-deleted function}}
// expected-note@-5 {{overridden virtual function is here}}
// expected-note@-6 3 {{destructor of 'Foo' is implicitly deleted because base class 'Base' has an inaccessible destructor}}
#endif

const int kBlah = 3;
#if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
#endif

Foo();
};

struct Bar : public Foo {
Bar() { } // expected-note {{implicit destructor for 'Foo' first required here}}
#if __cplusplus >= 201103L
// expected-error@-2 {{non-deleted function '~Bar' cannot override a deleted function}}
// expected-note@-3 {{while declaring the implicit destructor for 'Bar'}}
#endif
Bar() { }
#if __cplusplus <= 199711L
// expected-note@-2 {{implicit destructor for 'Foo' first required here}}
#else
// expected-error@-4 {{attempt to use a deleted function}}
#endif
};

struct Baz {
Foo f;
Baz() { }
#if __cplusplus >= 201103L
// expected-error@-2 {{attempt to use a deleted function}}
#endif
};
87 changes: 70 additions & 17 deletions clang/test/SemaCXX/default-assignment-operator.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

class Base { // expected-error {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator}} \
// expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
int &ref; // expected-note {{declared here}} \
// expected-note{{reference member 'ref' will never be initialized}}
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s

class Base { // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
#if __cplusplus <= 199711L
// expected-error@-2 {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator}}
#endif

int &ref; // expected-note{{reference member 'ref' will never be initialized}}
#if __cplusplus <= 199711L
// expected-note@-2 {{declared here}}
#else
// expected-note@-4 2 {{copy assignment operator of 'Base' is implicitly deleted because field 'ref' is of reference type 'int &'}}
#endif
};

class X : Base { // // expected-error {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator}} \
// expected-note{{assignment operator for 'Base' first required here}}
class X : Base {
#if __cplusplus <= 199711L
// expected-note@-2 {{assignment operator for 'Base' first required here}}
// expected-error@-3 {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator}}
#else
// expected-note@-5 2 {{copy assignment operator of 'X' is implicitly deleted because base class 'Base' has a deleted copy assignment operator}}
#endif

public:
X();
const int cint; // expected-note {{declared here}}
const int cint;
#if __cplusplus <= 199711L
// expected-note@-2 {{declared here}}
#endif
};

struct Y : X {
Expand All @@ -28,8 +46,17 @@ Z z2;

// Test1
void f(X x, const X cx) {
x = cx; // expected-note{{assignment operator for 'X' first required here}}
x = cx;
#if __cplusplus <= 199711L
// expected-note@-2 {{assignment operator for 'X' first required here}}
#else
// expected-error@-4 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}
#endif

x = cx;
#if __cplusplus >= 201103L
// expected-error@-2 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}
#endif
z1 = z2;
}

Expand Down Expand Up @@ -73,36 +100,62 @@ void i() {

// Test5

class E1 { // expected-error{{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator}}
class E1 {
#if __cplusplus <= 199711L
// expected-error@-2 {{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator}}
#endif

public:
const int a; // expected-note{{declared here}}
E1() : a(0) {}
const int a;
#if __cplusplus <= 199711L
// expected-note@-2 {{declared here}}
#else
// expected-note@-4 {{copy assignment operator of 'E1' is implicitly deleted because field 'a' is of const-qualified type 'const int'}}
#endif
E1() : a(0) {}

};

E1 e1, e2;

void j() {
e1 = e2; // expected-note{{assignment operator for 'E1' first required here}}
e1 = e2;
#if __cplusplus <= 199711L
// expected-note@-2 {{assignment operator for 'E1' first required here}}
#else
// expected-error@-4 {{object of type 'E1' cannot be assigned because its copy assignment operator is implicitly deleted}}
#endif
}

namespace ProtectedCheck {
struct X {
protected:
X &operator=(const X&); // expected-note{{declared protected here}}
X &operator=(const X&);
#if __cplusplus <= 199711L
// expected-note@-2 {{declared protected here}}
#endif
};

struct Y : public X { };

void f(Y y) { y = y; }

struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}}
struct Z {
#if __cplusplus <= 199711L
// expected-error@-2 {{'operator=' is a protected member of 'ProtectedCheck::X'}}
#endif
X x;
#if __cplusplus >= 201103L
// expected-note@-2 {{copy assignment operator of 'Z' is implicitly deleted because field 'x' has an inaccessible copy assignment operator}}
#endif
};

void f(Z z) { z = z; } // expected-note{{implicit copy assignment operator}}

void f(Z z) { z = z; }
#if __cplusplus <= 199711L
// expected-note@-2 {{implicit copy assignment operator}}
#else
// expected-error@-4 {{object of type 'ProtectedCheck::Z' cannot be assigned because its copy assignment operator is implicitly deleted}}
#endif
}

namespace MultiplePaths {
Expand Down
81 changes: 66 additions & 15 deletions clang/test/SemaCXX/default-constructor-initializers.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
// 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 X1 { // has no implicit default constructor
X1(int);
};

struct X2 : X1 { // expected-note 2 {{'X2' declared here}}
struct X2 : X1 {
#if __cplusplus <= 199711L
// expected-note@-2 2 {{'X2' declared here}}
#endif

X2(int);
};

struct X3 : public X2 { // expected-error {{implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor}}
struct X3 : public X2 {
#if __cplusplus <= 199711L
// expected-error@-2 {{implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor}}
#else
// expected-note@-4 {{default constructor of 'X3' is implicitly deleted because base class 'X2' has no default constructor}}
#endif
};
X3 x3; // expected-note {{first required here}}


struct X4 { // expected-error {{must explicitly initialize the member 'x2'}} \
// expected-error {{must explicitly initialize the reference member 'rx2'}}
X2 x2; // expected-note {{member is declared here}}
X2 & rx2; // expected-note {{declared here}}
X3 x3;
#if __cplusplus <= 199711L
// expected-note@-2 {{first required here}}
#else
// expected-error@-4 {{call to implicitly-deleted default constructor of 'X3'}}
#endif

struct X4 {
#if __cplusplus <= 199711L
// expected-error@-2 {{must explicitly initialize the member 'x2'}}
// expected-error@-3 {{must explicitly initialize the reference member 'rx2'}}
#endif

X2 x2;
#if __cplusplus <= 199711L
// expected-note@-2 {{member is declared here}}
#else
// expected-note@-4 {{default constructor of 'X4' is implicitly deleted because field 'x2' has no default constructor}}
#endif

X2 & rx2;
#if __cplusplus <= 199711L
// expected-note@-2 {{declared here}}
#endif
};

X4 x4; // expected-note {{first required here}}

X4 x4;
#if __cplusplus <= 199711L
// expected-note@-2 {{first required here}}
#else
// expected-error@-4 {{call to implicitly-deleted default constructor of 'X4'}}
#endif

struct Y1 { // has no implicit default constructor
Y1(int);
Expand All @@ -43,15 +76,33 @@ Y4 y4;

// More tests

struct Z1 { // expected-error {{must explicitly initialize the reference member 'z'}} \
// expected-error {{must explicitly initialize the const member 'c1'}}
int& z; // expected-note {{declared here}}
const int c1; // expected-note {{declared here}}
struct Z1 {
#if __cplusplus <= 199711L
// expected-error@-2 {{must explicitly initialize the reference member 'z'}}
// expected-error@-3 {{must explicitly initialize the const member 'c1'}}
#endif

int& z;
#if __cplusplus <= 199711L
// expected-note@-2 {{declared here}}
#else
// expected-note@-4 {{default constructor of 'Z1' is implicitly deleted because field 'z' of reference type 'int &' would not be initialized}}
#endif

const int c1;
#if __cplusplus <= 199711L
// expected-note@-2 {{declared here}}
#endif
volatile int v1;
};

// Test default initialization which *requires* a constructor call for non-POD.
Z1 z1; // expected-note {{first required here}}
Z1 z1;
#if __cplusplus <= 199711L
// expected-note@-2 {{first required here}}
#else
// expected-error@-4 {{call to implicitly-deleted default constructor of 'Z1'}}
#endif

// Ensure that value initialization doesn't use trivial implicit constructors.
namespace PR7948 {
Expand Down
Loading

0 comments on commit 6de8aca

Please sign in to comment.