diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref')
-rw-r--r-- | clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p5.cpp | 145 | ||||
-rw-r--r-- | clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p6-0x.cpp | 26 |
2 files changed, 171 insertions, 0 deletions
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p5.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p5.cpp new file mode 100644 index 0000000..c02105c --- /dev/null +++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p5.cpp @@ -0,0 +1,145 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// C++ [dcl.ref]p5: +// There shall be no references to references, no arrays of +// references, and no pointers to references. + +// The crazy formatting in here is to enforce the exact report locations. + +typedef int &intref; +typedef intref &intrefref; + +template <class T> class RefMem { // expected-warning{{class 'RefMem<int &>' does not declare any constructor to initialize its non-modifiable members}} + T + & + member; // expected-note{{reference member 'member' will never be initialized}} +}; + +struct RefRef { + int + & + & // expected-error {{declared as a reference to a reference}} + refref0; + + intref + & + refref1; // collapses + + intrefref + & + refref2; // collapses + + RefMem + < + int + & + > + refref3; // collapses expected-note{{in instantiation of template class 'RefMem<int &>' requested here}} +}; + + +template <class T> class PtrMem { + T + * // expected-error {{declared as a pointer to a reference}} + member; +}; + +struct RefPtr { + typedef + int + & + * // expected-error {{declared as a pointer to a reference}} + intrefptr; + + typedef + intref + * // expected-error {{declared as a pointer to a reference}} + intrefptr2; + + int + & + * // expected-error {{declared as a pointer to a reference}} + refptr0; + + intref + * // expected-error {{declared as a pointer to a reference}} + refptr1; + + PtrMem + < + int + & + > + refptr2; // expected-note {{in instantiation}} +}; + +template <class T> class ArrMem { + T + member + [ // expected-error {{declared as array of references}} + 10 + ]; +}; +template <class T, unsigned N> class DepArrMem { + T + member + [ // expected-error {{declared as array of references}} + N + ]; +}; + +struct RefArr { + typedef + int + & + intrefarr + [ // expected-error {{declared as array of references}} + 2 + ]; + + typedef + intref + intrefarr + [ // expected-error {{declared as array of references}} + 2 + ]; + + int + & + refarr0 + [ // expected-error {{declared as array of references}} + 2 + ]; + intref + refarr1 + [ // expected-error {{declared as array of references}} + 2 + ]; + ArrMem + < + int + & + > + refarr2; // expected-note {{in instantiation}} + DepArrMem + < + int + &, + 10 + > + refarr3; // expected-note {{in instantiation}} +}; + + +// The declaration of a reference shall contain an initializer +// (8.5.3) except when the declaration contains an explicit extern +// specifier (7.1.1), is a class member (9.2) declaration within a +// class definition, or is the declaration of a parameter or a +// return type (8.3.5); see 3.1. A reference shall be initialized to +// refer to a valid object or function. [ Note: in particular, a +// null reference cannot exist in a well-defined program, because +// the only way to create such a reference would be to bind it to +// the "object" obtained by dereferencing a null pointer, which +// causes undefined behavior. As described in 9.6, a reference +// cannot be bound directly to a bit-field. + diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p6-0x.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p6-0x.cpp new file mode 100644 index 0000000..4ce80bc --- /dev/null +++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p6-0x.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s + +template<typename T, typename U> +struct is_same { + static const bool value = false; +}; + +template<typename T> +struct is_same<T, T> { + static const bool value = true; +}; +#define JOIN2(X,Y) X##Y +#define JOIN(X,Y) JOIN2(X,Y) +#define CHECK_EQUAL_TYPES(T1, T2) \ + int JOIN(array,__LINE__)[is_same<T1, T2>::value? 1 : -1] + +int i; +typedef int& LRI; +typedef int&& RRI; + +typedef LRI& r1; CHECK_EQUAL_TYPES(r1, int&); +typedef const LRI& r2; CHECK_EQUAL_TYPES(r2, int&); +typedef const LRI&& r3; CHECK_EQUAL_TYPES(r3, int&); + +typedef RRI& r4; CHECK_EQUAL_TYPES(r4, int&); +typedef RRI&& r5; CHECK_EQUAL_TYPES(r5, int&&); |