llvm-project
81 строка · 2.2 Кб
1// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -std=c++11 %s 2>&1 | FileCheck %s
2
3template<typename T, typename U>
4struct pair {};
5
6template<typename T, typename U>
7struct map {
8typedef pair<T,U> *iterator;
9iterator begin();
10iterator end();
11};
12
13template<typename T, typename U>
14pair<T,U> &tie(T &, U &);
15
16int foo(map<char*,int> &m) {
17char *p;
18int n;
19
20for (pair<char*,int> x : m) {
21(void)x;
22}
23
24for (tie(p, n) : m) { // expected-error {{for range declaration must declare a variable}}
25(void)p;
26(void)n;
27}
28
29return n;
30}
31
32namespace PR19176 {
33struct Vector {
34struct iterator {
35int &operator*();
36iterator &operator++();
37iterator &operator++(int);
38bool operator==(const iterator &) const;
39};
40iterator begin();
41iterator end();
42};
43
44void f() {
45Vector v;
46int a[] = {1, 2, 3, 4};
47for (auto foo = a) // expected-error {{range-based 'for' statement uses ':', not '='}}
48// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:20}:":"
49(void)foo;
50for (auto i
51=
52v) // expected-error@-1 {{range-based 'for' statement uses ':', not '='}}
53// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:8}:":"
54(void)i;
55#define FORRANGE(v, a) for (DECLVARWITHINIT(v) a) // expected-note {{expanded from macro}}
56#define DECLAUTOVAR(v) auto v
57#define DECLVARWITHINIT(v) DECLAUTOVAR(v) = // expected-note {{expanded from macro}}
58FORRANGE(i, a) { // expected-error {{range-based 'for' statement uses ':', not '='}}
59
60}
61}
62}
63
64namespace GH63010 {
65void foo(int n) {
66int a[] = {1, 2, 3, 4, 5};
67{
68for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}} \
69// expected-error {{expected expression}}
70for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}}
71}
72{
73for (auto x = n ? 1 : 2 : a) // expected-error {{expected ';' in 'for' statement specifier}} \
74// expected-error {{expected expression}}
75
76} // expected-error {{expected statement}}
77{
78for (int i = 1; auto x = n ? 1 : 2 : a) // expected-error {{expected ';' in 'for' statement specifier}}
79} // expected-error {{expected statement}}
80}
81}
82