[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / for-range-no-std.cpp
blob66b445e4d83b63a1583873e00674213a2e977241
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions
4 struct S {
5 int *begin();
6 int *end();
7 };
9 struct T {
12 struct Range {};
13 int begin(Range); // expected-note {{not viable}}
14 int end(Range);
16 namespace NS {
17 struct ADL {};
18 struct iter {
19 int operator*();
20 bool operator!=(iter);
21 void operator++();
23 iter begin(ADL); // expected-note {{not viable}}
24 iter end(ADL);
26 struct NoADL {};
28 NS::iter begin(NS::NoADL); // expected-note {{not viable}}
29 NS::iter end(NS::NoADL);
31 void f() {
32 int a[] = {1, 2, 3};
33 for (auto b : S()) {} // ok
34 for (auto b : T()) {} // expected-error {{invalid range expression of type 'T'}}
35 for (auto b : a) {} // ok
36 for (int b : NS::ADL()) {} // ok
37 for (int b : NS::NoADL()) {} // expected-error {{invalid range expression of type 'NS::NoADL'}}
40 void PR11601() {
41 void (*vv[])() = {PR11601, PR11601, PR11601};
42 for (void (*i)() : vv) i();