From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaCXX/alias-template.cpp | 147 ++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 clang/test/SemaCXX/alias-template.cpp (limited to 'clang/test/SemaCXX/alias-template.cpp') diff --git a/clang/test/SemaCXX/alias-template.cpp b/clang/test/SemaCXX/alias-template.cpp new file mode 100644 index 0000000..484dd33 --- /dev/null +++ b/clang/test/SemaCXX/alias-template.cpp @@ -0,0 +1,147 @@ +// RUN: %clang_cc1 -verify -std=c++11 %s + +namespace RedeclAliasTypedef { + template using T = int; + template using T = int; + template using T = T; +} + +namespace IllegalTypeIds { + template using A = void(int n = 0); // expected-error {{default arguments can only be specified for parameters in a function declaration}} + template using B = inline void(int n); // expected-error {{type name does not allow function specifier}} + template using C = virtual void(int n); // expected-error {{type name does not allow function specifier}} + template using D = explicit void(int n); // expected-error {{type name does not allow function specifier}} + template using E = void(int n) throw(); // expected-error {{exception specifications are not allowed in type aliases}} + template using F = void(*)(int n) &&; // expected-error {{pointer to function type cannot have '&&' qualifier}} + template using G = __thread void(int n); // expected-error {{type name does not allow storage class to be specified}} + template using H = constexpr int; // expected-error {{type name does not allow constexpr specifier}} + + template using Y = void(int n); // ok + template using Z = void(int n) &&; // ok +} + +namespace IllegalSyntax { + template using ::T = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} + template using operator int = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} + template using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}} + template using typename ::V = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} + template using typename ::operator bool = void(int n); // expected-error {{name defined in alias declaration must be an identifier}} +} + +namespace VariableLengthArrays { + template using T = int[42]; // ok + + int n = 32; + template using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}} + + const int m = 42; + template using U = int[m]; // expected-note {{previous definition}} + template using U = int[42]; // ok + template using U = int; // expected-error {{type alias template redefinition with different types ('int' vs 'int [42]')}} +} + +namespace RedeclFunc { + int f(int, char**); + template using T = int; + T f(int, char **); // ok +} + +namespace LookupFilter { + namespace N { template using S = int; } + using namespace N; + template using S = S*; // ok +} + +namespace InFunctions { + template struct S0 { + template using U = T*; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} + U u; + }; + + template using T1 = int; + template using T2 = int[-1]; // expected-error {{array size is negative}} + template struct S3 { // expected-note {{template parameter is declared here}} + template using T = int; // expected-error {{declaration of 'T' shadows template parameter}} + }; + template using Z = Z; +} + +namespace ClassNameRedecl { + class C0 { + // FIXME: this diagnostic is pretty poor + template using C0 = int; // expected-error {{name defined in alias declaration must be an identifier}} + }; + class C1 { + // FIXME: this diagnostic is pretty poor + template using C1 = C1; // expected-error {{name defined in alias declaration must be an identifier}} + }; + class C2 { + template using C0 = C1; // ok + }; + template class C3 { + template using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} + }; + template class C4 { // expected-note {{template parameter is declared here}} + template using T = int; // expected-error {{declaration of 'T' shadows template parameter}} + }; + class C5 { + class c; // expected-note {{previous definition}} + template using c = int; // expected-error {{redefinition of 'c' as different kind of symbol}} + class d; // expected-note {{previous definition}} + template using d = d; // expected-error {{redefinition of 'd' as different kind of symbol}} + }; + class C6 { + class c { template using C6 = int; }; // ok + }; +} + +class CtorDtorName { + template using X = CtorDtorName; + X(); // expected-error {{expected member name}} + ~X(); // expected-error {{destructor cannot be declared using a type alias}} +}; + +namespace TagName { + template using S = struct { int n; }; // expected-error {{can not be defined}} + template using T = class { int n; }; // expected-error {{can not be defined}} + template using U = enum { a, b, c }; // expected-error {{can not be defined}} + template using V = struct V { int n; }; // expected-error {{redefinition of 'V' as different kind of symbol}} \ + expected-error {{'TagName::V' can not be defined in a type alias template}} \ + expected-note {{previous definition is here}} +} + +namespace StdExample { + template struct pair; + + template using handler_t = void (*)(T); + extern handler_t ignore; + extern void (*ignore)(int); + // FIXME: we recover as if cell is an undeclared variable. the diagnostics are terrible! + template using cell = pair*>; // expected-error {{use of undeclared identifier 'cell'}} \ + expected-error {{'T' does not refer to a value}} \ + expected-note {{declared here}} \ + expected-error {{expected ';' after alias declaration}} +} + +namespace Access { + class C0 { + template using U = int; // expected-note {{declared private here}} + }; + C0::U v; // expected-error {{'U' is a private member}} + class C1 { + public: + template using U = int; + }; + C1::U w; // ok +} + +namespace VoidArg { + template using V = void; + V f(int); // ok + V g(V); // expected-error {{empty parameter list defined with a type alias of 'void' not allowed}} +} + +namespace Curried { + template struct S; + template template using SS = S; // expected-error {{extraneous template parameter list in alias template declaration}} +} -- cgit v1.2.3