File: cxx2a-adl-only-template-id.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (75 lines) | stat: -rw-r--r-- 2,845 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// RUN: %clang_cc1 -std=c++2a -verify %s

namespace N {
  struct Q {};
  template<typename> int f(Q);
  template<int> int f(Q);
  template<typename> int g(Q);
  template<int> int g(Q);

  template<int> int some_long_name(Q); // expected-note {{here}}
}
N::Q q;
int g();

int h();
template<int> int h(...);
int h(int);

// OK, these find the above functions by ADL.
int a = f<int>(q);
int b(f<int>(q));
int c(f<0>(q));
int d = g<int>(q);

int e = h<0>(q); // ok, found by unqualified lookup

void fn() {
  f<0>(q);
  int f;
  f<0>(q); // expected-error {{invalid operands to binary expression}} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
}

void disambig() {
  // FIXME: It's unclear whether ending the template argument at the > inside the ?: is correct here (see DR579).
  f<true ? 1 > 2 : 3>(q); // expected-error {{expected ':'}} expected-note {{to match}} expected-error {{expected expression}}

  f < 1 + 3 > (q); // ok, function call
}

bool typo(int something) { // expected-note 4{{declared here}}
  // FIXME: We shouldn't suggest the N:: for an ADL call if the candidate can be found by ADL.
  some_logn_name<3>(q); // expected-error {{did you mean 'N::some_long_name'?}}
  somethign < 3 ? h() > 4 : h(0); // expected-error {{did you mean 'something'}}
  // This is parsed as a comparison on the left of a ?: expression.
  somethign < 3 ? h() + 4 : h(0); // expected-error {{did you mean 'something'}}
  // This is parsed as an ADL-only template-id call.
  somethign < 3 ? h() + 4 : h(0) >(0); // expected-error {{undeclared identifier 'somethign'}}
  bool k(somethign < 3); // expected-error {{did you mean 'something'}}
  return somethign < 3; // expected-error {{did you mean 'something'}}
}

// Ensure that treating undeclared identifiers as template names doesn't cause
// problems.
struct W<int> {}; // expected-error {{undeclared template struct 'W'}}
X<int>::Y xy; // expected-error {{no template named 'X'}}
void xf(X<int> x); // expected-error {{no template named 'X'}}
struct A : X<int> { // expected-error {{no template named 'X'}}
  A() : X<int>() {} // expected-error {{no template named 'X'}}
};

// Similarly for treating overload sets of functions as template names.
struct g<int> {}; // expected-error {{'g' refers to a function template}}
g<int>::Y xy; // expected-error {{no template named 'g'}} FIXME lies
void xf(g<int> x); // expected-error {{variable has incomplete type 'void'}} expected-error 1+{{}} expected-note {{}}
struct B : g<int> { // expected-error {{expected class name}}
  B() : g<int>() {} // expected-error {{expected class member or base class name}}
};

namespace vector_components {
  typedef __attribute__((__ext_vector_type__(2))) float vector_float2;
  bool foo123(vector_float2 &A, vector_float2 &B)
  {
    return A.x < B.x && B.y > A.y;
  }
}