comparison clang/test/SemaTemplate/temp_arg_template.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 1d019706d866
children
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
1 // RUN: %clang_cc1 -fsyntax-only -verify %s 1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s 2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 -std=c++17 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 3
5 template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}} 4 template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}}
6 5
7 template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}} 6 template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
8 7
17 template<class> struct Z; 16 template<class> struct Z;
18 } 17 }
19 template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}} 18 template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}}
20 19
21 20
22 A<X> *a1; 21 A<X> *a1;
23 A<N::Z> *a2; 22 A<N::Z> *a2;
24 A< ::N::Z> *a3; 23 A< ::N::Z> *a3;
25 24
26 A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}} 25 A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
27 A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}} 26 A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
40 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} 39 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
41 #endif 40 #endif
42 41
43 // Do not do a digraph correction here. 42 // Do not do a digraph correction here.
44 A<: :N::Z> *a11; // expected-error{{expected expression}} \ 43 A<: :N::Z> *a11; // expected-error{{expected expression}} \
45 expected-error{{C++ requires a type specifier for all declarations}} 44 precxx17-error{{a type specifier is required for all declarations}} \
45 cxx17-error{{expected unqualified-id}}
46 46
47 // PR7807 47 // PR7807
48 namespace N { 48 namespace N {
49 template <typename, typename = int> 49 template <typename, typename = int>
50 struct X 50 struct X
51 { }; 51 { };
52 52
53 template <typename ,int> 53 template <typename ,int>
54 struct Y 54 struct Y
55 { X<int> const_ref(); }; 55 { X<int> const_ref(); };
56 56
57 template <template<typename,int> class TT, typename T, int N> 57 template <template<typename,int> class TT, typename T, int N>
58 int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}} 58 int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}
59 0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}} 59 0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}
60 } 60 }
61 61
62 void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<Y, int, 1>' requested here}} 62 void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<N::Y, int, 1>' requested here}}
63 } 63 }
64 64
65 // PR12179 65 // PR12179
66 template <typename Primitive, template <Primitive...> class F> 66 template <typename Primitive, template <Primitive...> class F>
67 #if __cplusplus <= 199711L 67 #if __cplusplus <= 199711L
102 } 102 }
103 103
104 namespace CheckDependentNonTypeParamTypes { 104 namespace CheckDependentNonTypeParamTypes {
105 template<template<typename T, typename U, T v> class X> struct A { 105 template<template<typename T, typename U, T v> class X> struct A {
106 void f() { 106 void f() {
107 X<int, void*, 3> x; // expected-error {{does not refer to any declaration}} 107 X<int, void*, 3> x; // precxx17-error {{does not refer to any declaration}} \
108 cxx17-error {{value of type 'int' is not implicitly convertible to 'void *'}}
108 } 109 }
109 void g() { 110 void g() {
110 X<int, long, 3> x; 111 X<int, long, 3> x;
111 } 112 }
112 void h() { 113 void h() {
121 X<unsigned char, int, 1234> x; 122 X<unsigned char, int, 1234> x;
122 int check[x.value == 1234 ? 1 : -1]; 123 int check[x.value == 1234 ? 1 : -1];
123 } 124 }
124 }; 125 };
125 126
126 template<typename T, typename U, U v> struct B { // expected-note {{parameter}} 127 template<typename T, typename U, U v> struct B { // precxx17-note {{parameter}}
127 static const U value = v; 128 static const U value = v;
128 }; 129 };
129 130
130 // FIXME: This should probably be rejected, but the rules are at best unclear. 131 // FIXME: This should probably be rejected, but the rules are at best unclear.
131 A<B> ab; 132 A<B> ab;