cast-conversion.cpp revision 79ab2c8104ef5df233d271560ccc734836738e56
1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
2249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian
3249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanianstruct R {
4249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian  R(int);
5249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian};
6249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian
7249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanianstruct A {
8249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian  A(R);
9249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian};
10249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian
1179ab2c8104ef5df233d271560ccc734836738e56John McCallstruct B { // expected-note 3 {{candidate constructor (the implicit copy constructor) not viable}}
1279ab2c8104ef5df233d271560ccc734836738e56John McCall  B(A); // expected-note 3 {{candidate constructor not viable}}
13249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian};
14249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian
15249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanianint main () {
1679ab2c8104ef5df233d271560ccc734836738e56John McCall  B(10);	// expected-error {{no matching conversion for functional-style cast from 'int' to 'B'}}
1779ab2c8104ef5df233d271560ccc734836738e56John McCall  (B)10;	// expected-error {{no matching conversion for C-style cast from 'int' to 'B'}}
1879ab2c8104ef5df233d271560ccc734836738e56John McCall  static_cast<B>(10);	// expected-error {{no matching conversion for static_cast from 'int' to 'B'}} \\
191b2ad2fd9e2d5352144481aa1fd995d333d9adc9Argyrios Kyrtzidis			// expected-warning {{expression result unused}}
20249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian}
21249ceade4942a2a5d7888541c547abeda5bb85b4Fariborz Jahanian
22b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregortemplate<class T>
23b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregorstruct X0 {
24b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor  X0(const T &);
25b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor};
26b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor
27b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregortemplate<class T>
28b653c52d9176a4faecf923f792758f4454f7f78cDouglas GregorX0<T> make_X0(const T &Val) {
29b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor  return X0<T>(Val);
30b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor}
31b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor
32b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregorvoid test_X0() {
3360c93c9981c467738369702e7aa23fd58c2b6aacDouglas Gregor  const char array[2] = { 'a', 'b' };
34b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor  make_X0(array);
35b653c52d9176a4faecf923f792758f4454f7f78cDouglas Gregor}
3627591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor
3727591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor// PR5210 recovery
3827591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregorclass C {
3927591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregorprotected:
4027591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor  template <int> float* &f0(); // expected-note{{candidate}}
4127591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor  template <unsigned> float* &f0(); // expected-note{{candidate}}
4227591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor
4327591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor  void f1() {
4427591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor    static_cast<float*>(f0<0>()); // expected-error{{ambiguous}}
4527591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor  }
4627591ff4fc64600fd67c5d81899e3efe5ef41a80Douglas Gregor};
47